Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

vfs: check file exists in cache before renaming/setmodtime/deleting

Nick Craig-Wood6082096f7e63
diff --git a/vfs/file.go b/vfs/file.go
index 466b44a2f..db2bc8a27 100644
--- a/vfs/file.go
+++ b/vfs/file.go
@@ -211,7 +211,7 @@ func (f *File) rename(ctx context.Context, destDir *Dir, newName string) error {
}
}
// Rename in the cache
- if d.vfs.cache != nil {
+ if d.vfs.cache != nil && d.vfs.cache.Exists(oldPath) {
if err := d.vfs.cache.Rename(oldPath, newPath, newObject); err != nil {
fs.Infof(f.Path(), "File.Rename failed in Cache: %v", err)
}
@@ -366,7 +366,6 @@ func (f *File) _applyPendingModTime() error {
if f.pendingModTime.IsZero() {
return nil
}
-
defer func() { f.pendingModTime = time.Time{} }()
if f.o == nil {
@@ -377,16 +376,16 @@ func (f *File) _applyPendingModTime() error {
err := f.o.SetModTime(context.TODO(), f.pendingModTime)
switch err {
case nil:
- fs.Debugf(f._path(), "File._applyPendingModTime OK")
+ fs.Debugf(f.o, "Applied pending mod time %v OK", f.pendingModTime)
case fs.ErrorCantSetModTime, fs.ErrorCantSetModTimeWithoutDelete:
// do nothing, in order to not break "touch somefile" if it exists already
default:
- fs.Debugf(f._path(), "File._applyPendingModTime error: %v", err)
+ fs.Errorf(f.o, "Failed to apply pending mod time %v: %v", f.pendingModTime, err)
return err
}
// set the time of the file in the cache
- if f.d.vfs.cache != nil {
+ if f.d.vfs.cache != nil && f.d.vfs.cache.Exists(f._path()) {
f.d.vfs.cache.SetModTime(f._path(), f.pendingModTime)
}
@@ -537,7 +536,7 @@ func (f *File) Remove() (err error) {
// Remove the object from the cache
wasWriting := false
- if d.vfs.cache != nil {
+ if d.vfs.cache != nil && d.vfs.cache.Exists(f.Path()) {
wasWriting = d.vfs.cache.Remove(f.Path())
}