1
mirror of https://github.com/rclone/rclone synced 2024-12-26 18:23:45 +01:00

vfs: add non recursive mode to vfs/refresh rc command

This commit is contained in:
Fabian Möller 2018-07-30 00:30:32 +02:00 committed by Nick Craig-Wood
parent 782972088d
commit 6349147af4
2 changed files with 39 additions and 2 deletions

View File

@ -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.

View File

@ -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 {