Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vfs: add refresh flag #6840

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions vfs/vfscommon/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions vfs/vfsflags/vfsflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down