On rename, rename in cache too if the file exists

Signed-off-by: Anagh Kumar Baranwal <6824881+darthShadow@users.noreply.github.com>
This commit is contained in:
Anagh Kumar Baranwal
2019-08-26 18:13:11 +05:30
committed by Nick Craig-Wood
parent 5ddfa9f7f6
commit 5928704e1b
3 changed files with 48 additions and 2 deletions

View File

@@ -129,6 +129,14 @@ func (f *File) rename(ctx context.Context, destDir *Dir, newName string) error {
fs.Errorf(f.Path(), "File.Rename error: %v", err)
return err
}
// Rename in the cache too if it exists
if f.d.vfs.Opt.CacheMode >= CacheModeWrites && f.d.vfs.cache.exists(f.Path()) {
if err := f.d.vfs.cache.rename(f.Path(), newPath); err != nil {
fs.Infof(f.Path(), "File.Rename failed in Cache: %v", err)
}
}
// newObject can be nil here for example if --dry-run
if newObject == nil {
err = errors.New("rename failed: nil object returned")