From 2347762b0d0cedea2f118900599535b984ad1944 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 12 Nov 2020 17:46:13 +0000 Subject: [PATCH] vfs: fix "file already exists" error for stale cache files Before this change if a file was uploaded through a mount, then deleted externally, trying to upload that file again could give EEXIST "file already exists". This was because the file already existing in the cache was confusing rclone into thinking it already had the file. The fix is to check that if rclone has a stale cache file then to ignore it in this situation. See: https://forum.rclone.org/t/rclone-cant-reuse-filenames/20400 --- vfs/read_write.go | 2 +- vfs/vfscache/item.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/vfs/read_write.go b/vfs/read_write.go index 03d990c3a..b16eb663f 100644 --- a/vfs/read_write.go +++ b/vfs/read_write.go @@ -36,7 +36,7 @@ func newRWFileHandle(d *Dir, f *File, flags int) (fh *RWFileHandle, err error) { // get an item to represent this from the cache item := d.vfs.cache.Item(f.Path()) - exists := f.exists() || item.Exists() + exists := f.exists() || (item.Exists() && !item.WrittenBack()) // if O_CREATE and O_EXCL are set and if path already exists, then return EEXIST if flags&(os.O_CREATE|os.O_EXCL) == os.O_CREATE|os.O_EXCL && exists { diff --git a/vfs/vfscache/item.go b/vfs/vfscache/item.go index 9163e8ce9..158e583f2 100644 --- a/vfs/vfscache/item.go +++ b/vfs/vfscache/item.go @@ -808,6 +808,13 @@ func (item *Item) _checkObject(o fs.Object) error { return nil } +// WrittenBack checks to see if the item has been written back or not +func (item *Item) WrittenBack() bool { + item.mu.Lock() + defer item.mu.Unlock() + return item.info.Fingerprint != "" +} + // remove the cached file // // call with lock held