2018-10-26 20:52:27 +02:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
2019-06-17 10:34:30 +02:00
|
|
|
"context"
|
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/fs/rc"
|
2018-10-26 20:52:27 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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,
|
2019-06-17 10:34:30 +02:00
|
|
|
Fn: func(ctx context.Context, in rc.Params) (rc.Params, error) {
|
|
|
|
return rcSyncCopyMove(ctx, in, name)
|
2018-10-26 20:52:27 +02:00
|
|
|
},
|
|
|
|
Title: name + " a directory from source remote to destination remote",
|
2021-08-16 11:30:01 +02:00
|
|
|
Help: `This takes the following parameters:
|
2018-10-26 20:52:27 +02:00
|
|
|
|
2020-10-13 23:49:58 +02:00
|
|
|
- srcFs - a remote name string e.g. "drive:src" for the source
|
|
|
|
- dstFs - a remote name string e.g. "drive:dst" for the destination
|
2021-02-08 13:24:44 +01:00
|
|
|
- createEmptySrcDirs - create empty src directories on destination if set
|
2018-10-26 20:52:27 +02:00
|
|
|
` + moveHelp + `
|
|
|
|
|
2022-06-19 15:51:37 +02:00
|
|
|
See the [` + name + `](/commands/rclone_` + name + `/) command for more information on the above.`,
|
2018-10-26 20:52:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync/Copy/Move a file
|
2019-06-17 10:34:30 +02:00
|
|
|
func rcSyncCopyMove(ctx context.Context, in rc.Params, name string) (out rc.Params, err error) {
|
2020-11-05 16:18:51 +01:00
|
|
|
srcFs, err := rc.GetFsNamed(ctx, in, "srcFs")
|
2018-10-26 20:52:27 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-11-05 16:18:51 +01:00
|
|
|
dstFs, err := rc.GetFsNamed(ctx, in, "dstFs")
|
2018-10-26 20:52:27 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-03-06 09:43:46 +01:00
|
|
|
createEmptySrcDirs, err := in.GetBool("createEmptySrcDirs")
|
|
|
|
if rc.NotErrParamNotFound(err) {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-10-26 20:52:27 +02:00
|
|
|
switch name {
|
|
|
|
case "sync":
|
2019-06-17 10:34:30 +02:00
|
|
|
return nil, Sync(ctx, dstFs, srcFs, createEmptySrcDirs)
|
2018-10-26 20:52:27 +02:00
|
|
|
case "copy":
|
2019-06-17 10:34:30 +02:00
|
|
|
return nil, CopyDir(ctx, dstFs, srcFs, createEmptySrcDirs)
|
2018-10-26 20:52:27 +02:00
|
|
|
case "move":
|
|
|
|
deleteEmptySrcDirs, err := in.GetBool("deleteEmptySrcDirs")
|
|
|
|
if rc.NotErrParamNotFound(err) {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-06-17 10:34:30 +02:00
|
|
|
return nil, MoveDir(ctx, dstFs, srcFs, deleteEmptySrcDirs, createEmptySrcDirs)
|
2018-10-26 20:52:27 +02:00
|
|
|
}
|
|
|
|
panic("unknown rcSyncCopyMove type")
|
|
|
|
}
|