"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
vfs: file: fix some locking issues reading f.d without the lock
Nick Craig-Wood9a6fcd035b6e
diff --git a/vfs/file.go b/vfs/file.goindex 5a0cd5ca8..466b44a2f 100644--- a/vfs/file.go+++ b/vfs/file.go@@ -186,6 +186,7 @@ func (f *File) rename(ctx context.Context, destDir *Dir, newName string) error {f.mu.RLock()o := f.o+ d := f.df.mu.RUnlock()var newObject fs.Object// if o is nil then are writing the file so no need to rename the object@@ -210,8 +211,8 @@ func (f *File) rename(ctx context.Context, destDir *Dir, newName string) error {}}// Rename in the cache- if f.d.vfs.cache != nil {- if err := f.d.vfs.cache.Rename(oldPath, newPath, newObject); err != nil {+ if d.vfs.cache != nil {+ if err := d.vfs.cache.Rename(oldPath, newPath, newObject); err != nil {fs.Infof(f.Path(), "File.Rename failed in Cache: %v", err)}}@@ -241,7 +242,7 @@ func (f *File) rename(ctx context.Context, destDir *Dir, newName string) error {CacheMode := d.vfs.Opt.CacheModeif writing &&(CacheMode < vfscommon.CacheModeMinimal ||- (CacheMode == vfscommon.CacheModeMinimal && !f.d.vfs.cache.Exists(oldPath))) {+ (CacheMode == vfscommon.CacheModeMinimal && !destDir.vfs.cache.Exists(oldPath))) {fs.Debugf(oldPath, "File is currently open, delaying rename %p", f)f.mu.Lock()f.pendingRenameFun = renameCall@@ -342,11 +343,11 @@ func (f *File) Size() int64 {// SetModTime sets the modtime for the filefunc (f *File) SetModTime(modTime time.Time) error {+ f.mu.Lock()+ defer f.mu.Unlock()if f.d.vfs.Opt.ReadOnly {return EROFS}- f.mu.Lock()- defer f.mu.Unlock()f.pendingModTime = modTime@@ -408,10 +409,11 @@ func (f *File) setObject(o fs.Object) {f.mu.Lock()f.o = o_ = f._applyPendingModTime()+ d := f.df.mu.Unlock()// Release File.mu before calling Dir method- f.d.addObject(f)+ d.addObject(f)}// Update the object but don't update the directory cache - for use by