Skip to content

Commit

Permalink
moved handle lock into downloadFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Dabnsky committed Jun 11, 2024
1 parent a4e1366 commit 150b089
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions component/file_cache/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,9 @@ func (fc *FileCache) DeleteFile(options internal.DeleteFileOptions) error {
func (fc *FileCache) downloadFile(handle *handlemap.Handle) error {
log.Trace("FileCache::downloadFile : name=%s", handle.Path)

handle.Lock()
defer handle.Unlock()

//extract flags and mode out of the value from handle
var flags int
var fMode fs.FileMode
Expand Down Expand Up @@ -955,13 +958,11 @@ func (fc *FileCache) ReadInBuffer(options internal.ReadInBufferOptions) (int, er
// The file should already be in the cache since CreateFile/OpenFile was called before and a shared lock was acquired.
// log.Debug("FileCache::ReadInBuffer : Reading %v bytes from %s", len(options.Data), options.Handle.Path)

options.Handle.Lock()
var err error
err = fc.downloadFile(options.Handle)
if err != nil {
return 0, fmt.Errorf("error downloading file for %s [%s]", options.Handle.Path, err)
}
options.Handle.Unlock()

f := options.Handle.GetFileObject()
if f == nil {
Expand Down Expand Up @@ -993,13 +994,11 @@ func (fc *FileCache) WriteFile(options internal.WriteFileOptions) (int, error) {
// The file should already be in the cache since CreateFile/OpenFile was called before and a shared lock was acquired.
//log.Debug("FileCache::WriteFile : Writing %v bytes from %s", len(options.Data), options.Handle.Path)

options.Handle.Lock()
var err error
err = fc.downloadFile(options.Handle)
if err != nil {
return 0, fmt.Errorf("error downloading file for %s [%s]", options.Handle.Path, err)
}
options.Handle.Unlock()

f := options.Handle.GetFileObject()
if f == nil {
Expand Down

0 comments on commit 150b089

Please sign in to comment.