mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
vfs: check file exists in cache before renaming/setmodtime/deleting
Before this change we didn't check the file exists before renaming it, setting its modification time or deleting it. If the file isn't in the cache we don't need to do the action since it has been done on the actual object, so these errors were producing unecessary log messages. This change checks to see if the file exists first before doing those actions.
This commit is contained in:
parent
9a6fcd035b
commit
6082096f7e
11
vfs/file.go
11
vfs/file.go
@ -211,7 +211,7 @@ func (f *File) rename(ctx context.Context, destDir *Dir, newName string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Rename in the cache
|
// 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 {
|
if err := d.vfs.cache.Rename(oldPath, newPath, newObject); err != nil {
|
||||||
fs.Infof(f.Path(), "File.Rename failed in Cache: %v", err)
|
fs.Infof(f.Path(), "File.Rename failed in Cache: %v", err)
|
||||||
}
|
}
|
||||||
@ -366,7 +366,6 @@ func (f *File) _applyPendingModTime() error {
|
|||||||
if f.pendingModTime.IsZero() {
|
if f.pendingModTime.IsZero() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() { f.pendingModTime = time.Time{} }()
|
defer func() { f.pendingModTime = time.Time{} }()
|
||||||
|
|
||||||
if f.o == nil {
|
if f.o == nil {
|
||||||
@ -377,16 +376,16 @@ func (f *File) _applyPendingModTime() error {
|
|||||||
err := f.o.SetModTime(context.TODO(), f.pendingModTime)
|
err := f.o.SetModTime(context.TODO(), f.pendingModTime)
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
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:
|
case fs.ErrorCantSetModTime, fs.ErrorCantSetModTimeWithoutDelete:
|
||||||
// do nothing, in order to not break "touch somefile" if it exists already
|
// do nothing, in order to not break "touch somefile" if it exists already
|
||||||
default:
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the time of the file in the cache
|
// 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)
|
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
|
// Remove the object from the cache
|
||||||
wasWriting := false
|
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())
|
wasWriting = d.vfs.cache.Remove(f.Path())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user