Windows fix: path cleaning should use '/' not native path separators

Because we're comparing with Git which always uses '/' even on Windows
This commit is contained in:
Steve Streeting 2016-07-15 14:20:53 +01:00
parent bee70c086a
commit 0209c515b3

@ -5,6 +5,7 @@ package tools
import (
"fmt"
"os"
"path"
"path/filepath"
"strings"
)
@ -76,11 +77,12 @@ func RenameFileCopyPermissions(srcfile, destfile string) error {
}
// CleanPaths splits the given `paths` argument by the delimiter argument, and
// then "cleans" that path according to the filepath.Clean function (see
// https://golang.org/pkg/file/filepath#Clean).
// 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)
func CleanPaths(paths, delim string) (cleaned []string) {
// If paths is an empty string, splitting it will yield [""], which will
// become the filepath ".". To avoid this, bail out if trimmed paths
// become the path ".". To avoid this, bail out if trimmed paths
// argument is empty.
if paths = strings.TrimSpace(paths); len(paths) == 0 {
return
@ -89,7 +91,7 @@ func CleanPaths(paths, delim string) (cleaned []string) {
for _, part := range strings.Split(paths, delim) {
part = strings.TrimSpace(part)
cleaned = append(cleaned, filepath.Clean(part))
cleaned = append(cleaned, path.Clean(part))
}
return cleaned
@ -98,6 +100,7 @@ func CleanPaths(paths, delim string) (cleaned []string) {
// CleanPathsDefault cleans the paths contained in the given `paths` argument
// delimited by the `delim`, argument. If an empty set is returned from that
// split, then the fallback argument is returned instead.
// Note always cleans to '/' path separators regardless of platform (git friendly)
func CleanPathsDefault(paths, delim string, fallback []string) []string {
cleaned := CleanPaths(paths, delim)
if len(cleaned) == 0 {