MCPcopy
hub / github.com/rclone/rclone / transformPath

Function transformPath

lib/transform/transform.go:85–111  ·  view source on GitHub ↗

transformPath transforms a path string according to the chosen TransformAlgo. Each path segment is transformed separately, to preserve path separators. If baseOnly is true, only the base will be transformed (useful for renaming while walking a dir tree recursively.) for example, "some/nested/path" -

(s string, t transform, baseOnly bool)

Source from the content-addressed store, hash-verified

83// for example, "some/nested/path" -> "some/nested/CONVERTEDPATH"
84// otherwise, the entire is path is transformed.
85func transformPath(s string, t transform, baseOnly bool) (string, error) {
86 if s == "" || s == "/" || s == "\\" || s == "." {
87 return "", nil
88 }
89
90 if baseOnly {
91 transformedBase, err := transformPathSegment(path.Base(s), t)
92 if err := validateSegment(transformedBase); err != nil {
93 return "", err
94 }
95 return path.Join(path.Dir(s), transformedBase), err
96 }
97
98 segments := strings.Split(s, "/")
99 transformedSegments := make([]string, len(segments))
100 for _, seg := range segments {
101 convSeg, err := transformPathSegment(seg, t)
102 if err != nil {
103 return "", err
104 }
105 if err := validateSegment(convSeg); err != nil {
106 return "", err
107 }
108 transformedSegments = append(transformedSegments, convSeg)
109 }
110 return path.Join(transformedSegments...), nil
111}
112
113// transform all but the last path segment
114func transformDir(s string, t transform) (string, error) {

Callers 2

PathFunction · 0.85
transformDirFunction · 0.85

Calls 5

transformPathSegmentFunction · 0.85
validateSegmentFunction · 0.85
BaseMethod · 0.80
JoinMethod · 0.80
DirMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…