MCPcopy
hub / github.com/git-lfs/git-lfs / CleanPaths

Function CleanPaths

tools/filetools.go:93–116  ·  view source on GitHub ↗

CleanPaths splits the given `paths` argument by the delimiter argument, and then "cleans" that path according to the path.Clean function (see https://golang.org/pkg/path#Clean). Note always cleans to '/' path separators regardless of platform (git friendly)

(paths, delim string)

Source from the content-addressed store, hash-verified

91// https://golang.org/pkg/path#Clean).
92// Note always cleans to '/' path separators regardless of platform (git friendly)
93func CleanPaths(paths, delim string) (cleaned []string) {
94 // If paths is an empty string, splitting it will yield [""], which will
95 // become the path ".". To avoid this, bail out if trimmed paths
96 // argument is empty.
97 if paths = strings.TrimSpace(paths); len(paths) == 0 {
98 return
99 }
100
101 for _, part := range strings.Split(paths, delim) {
102 part = strings.TrimSpace(part)
103
104 // Remove trailing `/` or `\`, but only the first one.
105 for _, sep := range []string{`/`, `\`} {
106 if strings.HasSuffix(part, sep) {
107 part = strings.TrimSuffix(part, sep)
108 break
109 }
110 }
111
112 cleaned = append(cleaned, part)
113 }
114
115 return cleaned
116}
117
118// repositoryPermissionFetcher is an interface that matches the configuration
119// object and can be used to fetch repository permissions.

Calls

no outgoing calls