mirror of
https://github.com/rclone/rclone.git
synced 2025-12-06 00:03:32 +00:00
lib/transform: add transform library and --name-transform flag
lib/transform adds the transform library, supporting advanced path name transformations for converting and renaming files and directories by applying prefixes, suffixes, and other alterations. It also adds the --name-transform flag for use with sync, copy, and move. Multiple transformations can be used in sequence, applied in the order they are specified on the command line. By default --name-transform will only apply to file names. The means only the leaf file name will be transformed. However some of the transforms would be better applied to the whole path or just directories. To choose which which part of the file path is affected some tags can be added to the --name-transform: file Only transform the leaf name of files (DEFAULT) dir Only transform name of directories - these may appear anywhere in the path all Transform the entire path for files and directories Example syntax: --name-transform file,prefix=ABC --name-transform dir,prefix=DEF
This commit is contained in:
@@ -62,7 +62,7 @@ func rcList(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
if rc.NotErrParamNotFound(err) {
|
||||
return nil, err
|
||||
}
|
||||
var list = []*ListJSONItem{}
|
||||
list := []*ListJSONItem{}
|
||||
err = ListJSON(ctx, f, remote, &opt, func(item *ListJSONItem) error {
|
||||
list = append(list, item)
|
||||
return nil
|
||||
@@ -193,7 +193,7 @@ func rcMoveOrCopyFile(ctx context.Context, in rc.Params, cp bool) (out rc.Params
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, moveOrCopyFile(ctx, dstFs, srcFs, dstRemote, srcRemote, cp)
|
||||
return nil, moveOrCopyFile(ctx, dstFs, srcFs, dstRemote, srcRemote, cp, false)
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -289,7 +289,6 @@ func rcSingleCommand(ctx context.Context, in rc.Params, name string, noRemote bo
|
||||
|
||||
var request *http.Request
|
||||
request, err := in.GetHTTPRequest()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -629,12 +628,12 @@ func rcBackend(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var opt = map[string]string{}
|
||||
opt := map[string]string{}
|
||||
err = in.GetStructMissingOK("opt", &opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var arg = []string{}
|
||||
arg := []string{}
|
||||
err = in.GetStructMissingOK("arg", &arg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -642,7 +641,6 @@ func rcBackend(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
result, err := doCommand(ctx, command, arg, opt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("command %q failed: %w", command, err)
|
||||
|
||||
}
|
||||
out = make(rc.Params)
|
||||
out["result"] = result
|
||||
@@ -685,7 +683,6 @@ func rcDu(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
dir, err := in.GetString("dir")
|
||||
if rc.IsErrParamNotFound(err) {
|
||||
dir = config.GetCacheDir()
|
||||
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user