1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

vfs: Add recovered items on cache reload to directory listings

Before this change, if we restarted an upload after a restart then the
file would get uploaded but never added to the directory listings.

This change makes sure we add virtual items to the directory cache
when reloading the cache so that they show up properly.
This commit is contained in:
Nick Craig-Wood
2020-06-23 15:18:58 +01:00
parent 939860eb85
commit 15402e46c9
5 changed files with 65 additions and 3 deletions

View File

@@ -259,7 +259,7 @@ func (vfs *VFS) SetCacheMode(cacheMode vfscommon.CacheMode) {
vfs.cache = nil
if cacheMode > vfscommon.CacheModeOff {
ctx, cancel := context.WithCancel(context.Background())
cache, err := vfscache.New(ctx, vfs.f, &vfs.Opt) // FIXME pass on context or get from Opt?
cache, err := vfscache.New(ctx, vfs.f, &vfs.Opt, vfs.AddVirtual) // FIXME pass on context or get from Opt?
if err != nil {
fs.Errorf(nil, "Failed to create vfs cache - disabling: %v", err)
vfs.Opt.CacheMode = vfscommon.CacheModeOff
@@ -652,3 +652,13 @@ func (vfs *VFS) ReadFile(filename string) (b []byte, err error) {
defer fs.CheckClose(f, &err)
return ioutil.ReadAll(f)
}
// AddVirtual adds the object (file or dir) to the directory cache
func (vfs *VFS) AddVirtual(remote string, size int64, isDir bool) error {
dir, leaf, err := vfs.StatParent(remote)
if err != nil {
return err
}
dir.AddVirtual(leaf, size, false)
return nil
}