"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
vfs: add remote control for directory cache flushing
Nick Craig-Wood2db0c4dd9511
diff --git a/docs/content/rc.md b/docs/content/rc.mdindex 3d2dbc0af..bc45cec02 100644--- a/docs/content/rc.md+++ b/docs/content/rc.md@@ -9,6 +9,8 @@ date: "2018-03-05"If rclone is run with the `--rc` flag then it starts an http serverwhich can be used to remote control rclone.+**NB** this is experimental and everything here is subject to change!+## Supported parameters#### --rc ####@@ -54,6 +56,58 @@ rc` command.You can use it like this+```+$ rclone rc rc/noop param1=one param2=two+{+ "param1": "one",+ "param2": "two"+}+```++Run `rclone rc` on its own to see the help for the installed remote+control commands.++## Supported commands++### cache/expire: Purge a remote from cache++Purge a remote from the cache backend. Supports either a directory or a file.+Params:+ - remote = path to remote (required)+ - withData = true/false to delete cached data (chunks) as well (optional)++### vfs/forget: Forget files or directories in the directory cache.++This forgets the paths in the directory cache causing them to be+re-read from the remote when needed.++If no paths are passed in then it will forget all the paths in the+directory cache.++ rclone rc vfs/forget++Otherwise pass files or dirs in as file=path or dir=path. Any+parameter key starting with file will forget that file and any+starting with dir will forget that dir, eg++ rclone rc vfs/forget file=hello file2=goodbye dir=home/junk++### rc/noop: Echo the input to the output parameters++This echoes the input parameters to the output parameters for testing+purposes. It can be used to check that rclone is still alive and to+check that parameter passing is working properly.++### rc/error: This returns an error++This returns an error with the input as part of its error string.+Useful for testing error handling.++### rc/list: List all the registered remote control commands++This lists all the registered remote control commands as a JSON map in+the commands response.+## Accessing the remote control via HTTPRclone implements a simple HTTP based protocol.diff --git a/vfs/help.go b/vfs/help.goindex 8ed5407b1..51c293a19 100644--- a/vfs/help.go+++ b/vfs/help.go@@ -18,6 +18,15 @@ like this:kill -SIGHUP $(pidof rclone)+If you configure rclone with a [remote control](/rc) then you can use+rclone rc to flush the whole directory cache:++ rclone rc vfs/forget++Or individual files or directories:++ rclone rc vfs/forget file=path/to/file dir=path/to/dir+### File Caching**NB** File caching is **EXPERIMENTAL** - use with care!diff --git a/vfs/rc.go b/vfs/rc.gonew file mode 100644index 000000000..d7584eb75--- /dev/null+++ b/vfs/rc.go@@ -0,0 +1,64 @@+package vfs++import (+ "strings"++ "github.com/ncw/rclone/fs"+ "github.com/ncw/rclone/fs/rc"+ "github.com/pkg/errors"+)++// Add remote control for the VFS+func (vfs *VFS) addRC() {+ rc.Add(rc.Call{+ Path: "vfs/forget",+ Fn: func(in rc.Params) (out rc.Params, err error) {+ root, err := vfs.Root()+ if err != nil {+ return nil, err+ }++ forgotten := []string{}+ if len(in) == 0 {+ root.ForgetAll()+ } else {+ for k, v := range in {+ path, ok := v.(string)+ if !ok {+ return out, errors.Errorf("value must be string %q=%v", k, v)+ }+ path = strings.Trim(path, "/")+ if strings.HasPrefix(k, "file") {+ root.ForgetPath(path, fs.EntryObject)+ } else if strings.HasPrefix(k, "dir") {+ root.ForgetPath(path, fs.EntryDirectory)+ } else {+ return out, errors.Errorf("unknown key %q", k)+ }+ forgotten = append(forgotten, path)+ }+ }+ out = rc.Params{+ "forgotten": forgotten,+ }+ return out, nil+ },+ Title: "Forget files or directories in the directory cache.",+ Help: `+This forgets the paths in the directory cache causing them to be+re-read from the remote when needed.++If no paths are passed in then it will forget all the paths in the+directory cache.++ rclone rc vfs/forget++Otherwise pass files or dirs in as file=path or dir=path. Any+parameter key starting with file will forget that file and any+starting with dir will forget that dir, eg++ rclone rc vfs/forget file=hello file2=goodbye dir=home/junk++`,+ })+}diff --git a/vfs/vfs.go b/vfs/vfs.goindex e0fc4e5fb..e3cac7063 100644--- a/vfs/vfs.go+++ b/vfs/vfs.go@@ -233,6 +233,9 @@ func New(f fs.Fs, opt *Options) *VFS {panic(fmt.Sprintf("failed to create local cache: %v", err))}vfs.cache = cache++ // add the remote control+ vfs.addRC()return vfs}