mirror of
https://github.com/rclone/rclone.git
synced 2024-12-02 05:14:55 +01:00
e43b5ce5e5
This is possible now that we no longer support go1.12 and brings rclone into line with standard practices in the Go world. This also removes errors.New and errors.Errorf from lib/errors and prefers the stdlib errors package over lib/errors.
92 lines
2.1 KiB
Go
92 lines
2.1 KiB
Go
package bisync
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log"
|
|
|
|
"github.com/rclone/rclone/cmd/bisync/bilib"
|
|
"github.com/rclone/rclone/fs"
|
|
"github.com/rclone/rclone/fs/rc"
|
|
)
|
|
|
|
func init() {
|
|
rc.Add(rc.Call{
|
|
Path: "sync/bisync",
|
|
AuthRequired: true,
|
|
Fn: rcBisync,
|
|
Title: shortHelp,
|
|
Help: rcHelp,
|
|
})
|
|
}
|
|
|
|
func rcBisync(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
|
opt := &Options{}
|
|
octx, ci := fs.AddConfig(ctx)
|
|
|
|
if dryRun, err := in.GetBool("dryRun"); err == nil {
|
|
ci.DryRun = dryRun
|
|
} else if rc.NotErrParamNotFound(err) {
|
|
return nil, err
|
|
}
|
|
|
|
if maxDelete, err := in.GetInt64("maxDelete"); err == nil {
|
|
if maxDelete < 0 || maxDelete > 100 {
|
|
return nil, rc.NewErrParamInvalid(errors.New("maxDelete must be a percentage between 0 and 100"))
|
|
}
|
|
ci.MaxDelete = maxDelete
|
|
} else if rc.NotErrParamNotFound(err) {
|
|
return nil, err
|
|
}
|
|
|
|
if opt.Resync, err = in.GetBool("resync"); rc.NotErrParamNotFound(err) {
|
|
return
|
|
}
|
|
if opt.CheckAccess, err = in.GetBool("checkAccess"); rc.NotErrParamNotFound(err) {
|
|
return
|
|
}
|
|
if opt.Force, err = in.GetBool("force"); rc.NotErrParamNotFound(err) {
|
|
return
|
|
}
|
|
if opt.RemoveEmptyDirs, err = in.GetBool("removeEmptyDirs"); rc.NotErrParamNotFound(err) {
|
|
return
|
|
}
|
|
if opt.NoCleanup, err = in.GetBool("noCleanup"); rc.NotErrParamNotFound(err) {
|
|
return
|
|
}
|
|
|
|
if opt.CheckFilename, err = in.GetString("checkFilename"); rc.NotErrParamNotFound(err) {
|
|
return
|
|
}
|
|
if opt.FiltersFile, err = in.GetString("filtersFile"); rc.NotErrParamNotFound(err) {
|
|
return
|
|
}
|
|
if opt.Workdir, err = in.GetString("workdir"); rc.NotErrParamNotFound(err) {
|
|
return
|
|
}
|
|
|
|
checkSync, err := in.GetString("checkSync")
|
|
if rc.NotErrParamNotFound(err) {
|
|
return nil, err
|
|
}
|
|
if err := opt.CheckSync.Set(checkSync); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
fs1, err := rc.GetFsNamed(octx, in, "path1")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
fs2, err := rc.GetFsNamed(octx, in, "path2")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
output := bilib.CaptureOutput(func() {
|
|
err = Bisync(octx, fs1, fs2, opt)
|
|
})
|
|
_, _ = log.Writer().Write(output)
|
|
return rc.Params{"output": string(output)}, err
|
|
}
|