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 non recursive mode to vfs/refresh rc command

Fabian Möller6349147af49a
diff --git a/vfs/dir.go b/vfs/dir.go
index bfbda85a8..e1d92d0e8 100644
--- a/vfs/dir.go
+++ b/vfs/dir.go
@@ -256,6 +256,7 @@ func (d *Dir) _readDirFromEntries(entries fs.DirEntries, dirTree walk.DirTree, w
return nil
}
+// readDirTree forces a refresh of the complete directory tree
func (d *Dir) readDirTree() error {
d.mu.Lock()
defer d.mu.Unlock()
@@ -275,6 +276,14 @@ func (d *Dir) readDirTree() error {
return nil
}
+// readDir forces a refresh of the directory
+func (d *Dir) readDir() error {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+ d.read = time.Time{}
+ return d._readDir()
+}
+
// stat a single item in the directory
//
// returns ENOENT if not found.
diff --git a/vfs/rc.go b/vfs/rc.go
index 224e1856d..0d5a5a12d 100644
--- a/vfs/rc.go
+++ b/vfs/rc.go
@@ -86,9 +86,33 @@ starting with dir will forget that dir, eg
return nil, EINVAL
}
+ recursive := false
+ {
+ const k = "recursive"
+
+ if v, ok := in[k]; ok {
+ s, ok := v.(string)
+ if !ok {
+ return out, errors.Errorf("value must be string %q=%v", k, v)
+ }
+ switch strings.ToLower(s) {
+ case "true", "1":
+ recursive = true
+ case "false", "0":
+ default:
+ return out, errors.Errorf("invalid value %q=%v", k, v)
+ }
+ delete(in, k)
+ }
+ }
+
result := map[string]string{}
if len(in) == 0 {
- err = root.readDirTree()
+ if recursive {
+ err = root.readDirTree()
+ } else {
+ err = root.readDir()
+ }
if err != nil {
result[""] = err.Error()
} else {
@@ -105,7 +129,11 @@ starting with dir will forget that dir, eg
if err != nil {
result[path] = err.Error()
} else {
- err = dir.readDirTree()
+ if recursive {
+ err = dir.readDirTree()
+ } else {
+ err = dir.readDir()
+ }
if err != nil {
result[path] = err.Error()
} else {