"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: fix deletion of in use directories #1860
Nick Craig-Wood29d34426bc2c
diff --git a/vfs/cache.go b/vfs/cache.goindex 7a5d68ac1..838f37f20 100644--- a/vfs/cache.go+++ b/vfs/cache.go@@ -267,6 +267,9 @@ func (c *cache) removeDir(dir string) bool {osPath := c.toOSPath(dir)err := os.Remove(osPath)if err == nil || os.IsNotExist(err) {+ if err == nil {+ fs.Debugf(dir, "Removed empty directory")+ }return true}if !os.IsExist(err) {diff --git a/vfs/read_write.go b/vfs/read_write.goindex d13218a36..c95e26381 100644--- a/vfs/read_write.go+++ b/vfs/read_write.go@@ -39,12 +39,6 @@ var ()func newRWFileHandle(d *Dir, f *File, remote string, flags int) (fh *RWFileHandle, err error) {- // Make a place for the file- osPath, err := d.vfs.cache.mkdir(remote)- if err != nil {- return nil, errors.Wrap(err, "open RW handle failed to make cache directory")- }-// if O_CREATE and O_EXCL are set and if path already exists, then return EEXISTif flags&(os.O_CREATE|os.O_EXCL) == os.O_CREATE|os.O_EXCL && f.exists() {return nil, EEXIST@@ -56,7 +50,16 @@ func newRWFileHandle(d *Dir, f *File, remote string, flags int) (fh *RWFileHandld: d,remote: remote,flags: flags,- osPath: osPath,+ }++ // mark the file as open in the cache - must be done before the mkdir+ fh.d.vfs.cache.open(fh.remote)++ // Make a place for the file+ fh.osPath, err = d.vfs.cache.mkdir(remote)+ if err != nil {+ fh.d.vfs.cache.close(fh.remote)+ return nil, errors.Wrap(err, "open RW handle failed to make cache directory")}rdwrMode := fh.flags & accessModeMask@@ -129,7 +132,6 @@ func (fh *RWFileHandle) openPending(truncate bool) (err error) {}fh.File = fdfh.opened = true- fh.d.vfs.cache.open(fh.remote)fh.d.addObject(fh.file) // make sure the directory has this object in it nowreturn nil}@@ -167,6 +169,7 @@ func (fh *RWFileHandle) close() (err error) {return ECLOSED}fh.closed = true+ defer fh.d.vfs.cache.close(fh.remote)rdwrMode := fh.flags & accessModeMaskif rdwrMode != os.O_RDONLY {// leave writer open until file is transferred@@ -196,7 +199,6 @@ func (fh *RWFileHandle) close() (err error) {fh.file.setSize(fi.Size())}}- fh.d.vfs.cache.close(fh.remote)// Close the underlying fileerr = fh.File.Close()