Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

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

Beyond Meat3337fe31c742
diff --git a/vfs/vfs.go b/vfs/vfs.go
index 28041e964..82f926b50 100644
--- a/vfs/vfs.go
+++ b/vfs/vfs.go
@@ -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)
diff --git a/vfs/vfscommon/options.go b/vfs/vfscommon/options.go
index 06135593e..bb5f3313a 100644
--- a/vfs/vfscommon/options.go
+++ b/vfs/vfscommon/options.go
@@ -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,
diff --git a/vfs/vfsflags/vfsflags.go b/vfs/vfsflags/vfsflags.go
index b74c76d89..2f1adafde 100644
--- a/vfs/vfsflags/vfsflags.go
+++ b/vfs/vfsflags/vfsflags.go
@@ -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")