MCPcopy
hub / github.com/rclone/rclone / Path

Function Path

lib/transform/transform.go:43–78  ·  view source on GitHub ↗

Path transforms a path s according to the --name-transform options in use If no transforms are in use, s is returned unchanged

(ctx context.Context, s string, isDir bool)

Source from the content-addressed store, hash-verified

41//
42// If no transforms are in use, s is returned unchanged
43func Path(ctx context.Context, s string, isDir bool) string {
44 if !Transforming(ctx) {
45 return s
46 }
47
48 old := s
49 opt, err := getOptions(ctx)
50 if err != nil {
51 err = fs.CountError(ctx, err)
52 fs.Errorf(s, "Failed to parse transform flags: %v", err)
53 }
54 for _, t := range opt {
55 if isDir && t.tag == file {
56 continue
57 }
58 baseOnly := !isDir && t.tag == file
59 if t.tag == dir && !isDir {
60 s, err = transformDir(s, t)
61 } else {
62 s, err = transformPath(s, t, baseOnly)
63 }
64 if err != nil {
65 err = fs.CountError(ctx, fserrors.NoRetryError(err))
66 fs.Errorf(s, "Failed to transform: %v", err)
67 }
68 }
69 if old != s {
70 fs.Debugf(old, "transformed to: %v", s)
71 }
72 if strings.Count(old, "/") != strings.Count(s, "/") {
73 err = fs.CountError(ctx, fserrors.NoRetryError(fmt.Errorf("number of path segments must match: %v (%v), %v (%v)", old, strings.Count(old, "/"), s, strings.Count(s, "/"))))
74 fs.Errorf(old, "%v", err)
75 return old
76 }
77 return s
78}
79
80// transformPath transforms a path string according to the chosen TransformAlgo.
81// Each path segment is transformed separately, to preserve path separators.

Callers 15

outputMethod · 0.92
TestTransformFunction · 0.92
compareNamesFunction · 0.92
transformItemsFunction · 0.92
srcOrDstKeyMethod · 0.92
SrcOnlyMethod · 0.92
MatchMethod · 0.92
compareNamesFunction · 0.92
predictDstFromLoggerFunction · 0.92
CopyFunction · 0.92
moveFunction · 0.92
TestPathFunction · 0.85

Calls 9

ErrorfFunction · 0.92
NoRetryErrorFunction · 0.92
DebugfFunction · 0.92
TransformingFunction · 0.85
getOptionsFunction · 0.85
transformDirFunction · 0.85
transformPathFunction · 0.85
CountMethod · 0.65
ErrorfMethod · 0.45

Tested by 12

TestTransformFunction · 0.74
compareNamesFunction · 0.74
transformItemsFunction · 0.74
compareNamesFunction · 0.74
predictDstFromLoggerFunction · 0.74
TestPathFunction · 0.68
TestFileTagOnFileFunction · 0.68
TestDirTagOnFileFunction · 0.68
TestAllTagFunction · 0.68
TestFileTagOnDirFunction · 0.68
TestDirTagOnDirFunction · 0.68
TestVariousFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…