2018-10-27 02:52:27 +08:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ncw/rclone/fs/rc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
for _, name := range []string{"sync", "copy", "move"} {
|
|
|
|
name := name
|
|
|
|
moveHelp := ""
|
|
|
|
if name == "move" {
|
|
|
|
moveHelp = "- deleteEmptySrcDirs - delete empty src directories if set\n"
|
|
|
|
}
|
|
|
|
rc.Add(rc.Call{
|
|
|
|
Path: "sync/" + name,
|
|
|
|
AuthRequired: true,
|
|
|
|
Fn: func(in rc.Params) (rc.Params, error) {
|
|
|
|
return rcSyncCopyMove(in, name)
|
|
|
|
},
|
|
|
|
Title: name + " a directory from source remote to destination remote",
|
|
|
|
Help: `This takes the following parameters
|
|
|
|
|
|
|
|
- srcFs - a remote name string eg "drive:src" for the source
|
|
|
|
- dstFs - a remote name string eg "drive:dst" for the destination
|
|
|
|
` + moveHelp + `
|
|
|
|
|
|
|
|
See the [` + name + ` command](/commands/rclone_` + name + `/) command for more information on the above.`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync/Copy/Move a file
|
|
|
|
func rcSyncCopyMove(in rc.Params, name string) (out rc.Params, err error) {
|
|
|
|
srcFs, err := rc.GetFsNamed(in, "srcFs")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
dstFs, err := rc.GetFsNamed(in, "dstFs")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-03-06 16:43:46 +08:00
|
|
|
createEmptySrcDirs, err := in.GetBool("createEmptySrcDirs")
|
|
|
|
if rc.NotErrParamNotFound(err) {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-10-27 02:52:27 +08:00
|
|
|
switch name {
|
|
|
|
case "sync":
|
2019-03-06 16:43:46 +08:00
|
|
|
return nil, Sync(dstFs, srcFs, createEmptySrcDirs)
|
2018-10-27 02:52:27 +08:00
|
|
|
case "copy":
|
2019-03-06 16:43:46 +08:00
|
|
|
return nil, CopyDir(dstFs, srcFs, createEmptySrcDirs)
|
2018-10-27 02:52:27 +08:00
|
|
|
case "move":
|
|
|
|
deleteEmptySrcDirs, err := in.GetBool("deleteEmptySrcDirs")
|
|
|
|
if rc.NotErrParamNotFound(err) {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-03-06 16:43:46 +08:00
|
|
|
return nil, MoveDir(dstFs, srcFs, deleteEmptySrcDirs, createEmptySrcDirs)
|
2018-10-27 02:52:27 +08:00
|
|
|
}
|
|
|
|
panic("unknown rcSyncCopyMove type")
|
|
|
|
}
|