mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 09:11:11 +08:00
vfs: remove items from cache when deleted #1860
Also fixes Error message when items have been deleted from the cache (eg when Moved) when the cache reaper comes to delete them.
This commit is contained in:
parent
aab8051f50
commit
d1b19f975d
19
vfs/cache.go
19
vfs/cache.go
|
@ -181,6 +181,17 @@ func (c *cache) close(name string) {
|
|||
c.itemMu.Unlock()
|
||||
}
|
||||
|
||||
// remove should be called if name is deleted
|
||||
func (c *cache) remove(name string) {
|
||||
osPath := filepath.Join(c.root, filepath.FromSlash(name))
|
||||
err := os.Remove(osPath)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
fs.Errorf(name, "Failed to remove from cache: %v", err)
|
||||
} else {
|
||||
fs.Debugf(name, "Removed from cache")
|
||||
}
|
||||
}
|
||||
|
||||
// cleanUp empties the cache of everything
|
||||
func (c *cache) cleanUp() error {
|
||||
return os.RemoveAll(c.root)
|
||||
|
@ -219,13 +230,7 @@ func (c *cache) purgeOld(maxAge time.Duration) {
|
|||
dt := item.atime.Sub(cutoff)
|
||||
// fs.Debugf(name, "atime=%v cutoff=%v, dt=%v", item.atime, cutoff, dt)
|
||||
if item.opens == 0 && dt < 0 {
|
||||
osPath := filepath.Join(c.root, filepath.FromSlash(name))
|
||||
err := os.Remove(osPath)
|
||||
if err != nil {
|
||||
fs.Errorf(name, "Failed to remove from cache: %v", err)
|
||||
} else {
|
||||
fs.Debugf(name, "Removed from cache")
|
||||
}
|
||||
c.remove(name)
|
||||
// Remove the entry
|
||||
delete(c.item, name)
|
||||
}
|
||||
|
|
|
@ -314,6 +314,10 @@ func (f *File) Remove() error {
|
|||
}
|
||||
// Remove the item from the directory listing
|
||||
f.d.delObject(f.Name())
|
||||
// Remove the object from the cache
|
||||
if f.d.vfs.Opt.CacheMode >= CacheModeMinimal {
|
||||
f.d.vfs.cache.remove(f.Path())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user