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)
| 41 | // |
| 42 | // If no transforms are in use, s is returned unchanged |
| 43 | func 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. |
searching dependent graphs…