mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 09:41:44 +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()
|
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
|
// cleanUp empties the cache of everything
|
||||||
func (c *cache) cleanUp() error {
|
func (c *cache) cleanUp() error {
|
||||||
return os.RemoveAll(c.root)
|
return os.RemoveAll(c.root)
|
||||||
|
@ -219,13 +230,7 @@ func (c *cache) purgeOld(maxAge time.Duration) {
|
||||||
dt := item.atime.Sub(cutoff)
|
dt := item.atime.Sub(cutoff)
|
||||||
// fs.Debugf(name, "atime=%v cutoff=%v, dt=%v", item.atime, cutoff, dt)
|
// fs.Debugf(name, "atime=%v cutoff=%v, dt=%v", item.atime, cutoff, dt)
|
||||||
if item.opens == 0 && dt < 0 {
|
if item.opens == 0 && dt < 0 {
|
||||||
osPath := filepath.Join(c.root, filepath.FromSlash(name))
|
c.remove(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")
|
|
||||||
}
|
|
||||||
// Remove the entry
|
// Remove the entry
|
||||||
delete(c.item, name)
|
delete(c.item, name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -314,6 +314,10 @@ func (f *File) Remove() error {
|
||||||
}
|
}
|
||||||
// Remove the item from the directory listing
|
// Remove the item from the directory listing
|
||||||
f.d.delObject(f.Name())
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user