mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 08:23:47 +01:00
vfs: add non recursive mode to vfs/refresh rc command
This commit is contained in:
parent
782972088d
commit
6349147af4
@ -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.
|
||||
|
32
vfs/rc.go
32
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user