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
This commit is contained in:
Nick Craig-Wood 2020-11-12 17:46:13 +00:00
parent 636fb5344a
commit 2347762b0d
2 changed files with 8 additions and 1 deletions

View File

@ -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 {

View File

@ -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