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)

View File

@ -15,6 +15,7 @@ type Options struct {
ReadOnly bool // if set VFS is read only
NoModTime bool // don't read mod times for files
DirCacheTime time.Duration // how long to consider directory listing cache valid
Refresh bool // refreshes the directory listing recursively on start
PollInterval time.Duration
Umask int
UID uint32
@ -44,6 +45,7 @@ var DefaultOpt = Options{
NoChecksum: false,
NoSeek: false,
DirCacheTime: 5 * 60 * time.Second,
Refresh: false,
PollInterval: time.Minute,
ReadOnly: false,
Umask: 0,

View File

@ -22,6 +22,7 @@ func AddFlags(flagSet *pflag.FlagSet) {
flags.BoolVarP(flagSet, &Opt.NoChecksum, "no-checksum", "", Opt.NoChecksum, "Don't compare checksums on up/download", "VFS")
flags.BoolVarP(flagSet, &Opt.NoSeek, "no-seek", "", Opt.NoSeek, "Don't allow seeking in files", "VFS")
flags.DurationVarP(flagSet, &Opt.DirCacheTime, "dir-cache-time", "", Opt.DirCacheTime, "Time to cache directory entries for", "VFS")
flags.BoolVarP(flagSet, &Opt.Refresh, "vfs-refresh", "", Opt.Refresh, "Refreshes the directory cache recursively on start", "VFS")
flags.DurationVarP(flagSet, &Opt.PollInterval, "poll-interval", "", Opt.PollInterval, "Time to wait between polling for changes, must be smaller than dir-cache-time and only on supported remotes (set 0 to disable)", "VFS")
flags.BoolVarP(flagSet, &Opt.ReadOnly, "read-only", "", Opt.ReadOnly, "Only allow read-only access", "VFS")
flags.FVarP(flagSet, &Opt.CacheMode, "vfs-cache-mode", "", "Cache mode off|minimal|writes|full", "VFS")