vfs: add --vfs-refresh flag to read all the directories on start

Refreshes the directory listing recursively at VFS start time.
This commit is contained in:
Beyond Meat
2023-09-08 06:41:12 -07:00
committed by Nick Craig-Wood
parent a752563842
commit 3337fe31c7
3 changed files with 17 additions and 0 deletions

View File

@@ -232,12 +232,26 @@ func New(f fs.Fs, opt *vfscommon.Options) *VFS {
// removed when the vfs is finalized
cache.PinUntilFinalized(f, vfs)
// Refresh the dircache if required
if vfs.Opt.Refresh {
go vfs.refresh()
}
// This can take some time so do it after the Pin
vfs.SetCacheMode(vfs.Opt.CacheMode)
return vfs
}
// refresh the directory cache for all directories
func (vfs *VFS) refresh() {
fs.Debugf(vfs.f, "Refreshing VFS directory cache")
err := vfs.root.readDirTree()
if err != nil {
fs.Errorf(vfs.f, "Error refreshing VFS directory cache: %v", err)
}
}
// Stats returns info about the VFS
func (vfs *VFS) Stats() (out rc.Params) {
out = make(rc.Params)