mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 13:26:11 +08:00
vfs: add remote control for directory cache flushing
This commit is contained in:
parent
5bf639048f
commit
2db0c4dd95
|
@ -9,6 +9,8 @@ date: "2018-03-05"
|
|||
If rclone is run with the `--rc` flag then it starts an http server
|
||||
which 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 HTTP
|
||||
|
||||
Rclone implements a simple HTTP based protocol.
|
||||
|
|
|
@ -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!
|
||||
|
|
64
vfs/rc.go
Normal file
64
vfs/rc.go
Normal file
|
@ -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
|
||||
|
||||
`,
|
||||
})
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user