Signed-off-by: John Howard <jhoward@microsoft.com>
| ... | ... |
@@ -52,7 +52,7 @@ func CleanPatterns(patterns []string) ([]string, [][]string, bool, error) {
|
| 52 | 52 |
if exclusion(pattern) {
|
| 53 | 53 |
pattern = pattern[1:] |
| 54 | 54 |
} |
| 55 |
- patternDirs = append(patternDirs, strings.Split(pattern, "/")) |
|
| 55 |
+ patternDirs = append(patternDirs, strings.Split(pattern, string(os.PathSeparator))) |
|
| 56 | 56 |
} |
| 57 | 57 |
|
| 58 | 58 |
return cleanedPatterns, patternDirs, exceptions, nil |
| ... | ... |
@@ -83,8 +83,9 @@ func Matches(file string, patterns []string) (bool, error) {
|
| 83 | 83 |
// The more generic fileutils.Matches() can't make these assumptions. |
| 84 | 84 |
func OptimizedMatches(file string, patterns []string, patDirs [][]string) (bool, error) {
|
| 85 | 85 |
matched := false |
| 86 |
+ file = filepath.FromSlash(file) |
|
| 86 | 87 |
parentPath := filepath.Dir(file) |
| 87 |
- parentPathDirs := strings.Split(parentPath, "/") |
|
| 88 |
+ parentPathDirs := strings.Split(parentPath, string(os.PathSeparator)) |
|
| 88 | 89 |
|
| 89 | 90 |
for i, pattern := range patterns {
|
| 90 | 91 |
negative := false |
| ... | ... |
@@ -102,8 +103,8 @@ func OptimizedMatches(file string, patterns []string, patDirs [][]string) (bool, |
| 102 | 102 |
if !match && parentPath != "." {
|
| 103 | 103 |
// Check to see if the pattern matches one of our parent dirs. |
| 104 | 104 |
if len(patDirs[i]) <= len(parentPathDirs) {
|
| 105 |
- match, _ = regexpMatch(strings.Join(patDirs[i], "/"), |
|
| 106 |
- strings.Join(parentPathDirs[:len(patDirs[i])], "/")) |
|
| 105 |
+ match, _ = regexpMatch(strings.Join(patDirs[i], string(os.PathSeparator)), |
|
| 106 |
+ strings.Join(parentPathDirs[:len(patDirs[i])], string(os.PathSeparator))) |
|
| 107 | 107 |
} |
| 108 | 108 |
} |
| 109 | 109 |
|
| ... | ... |
@@ -125,6 +126,9 @@ func OptimizedMatches(file string, patterns []string, patDirs [][]string) (bool, |
| 125 | 125 |
// of directories. This means that we should be backwards compatible |
| 126 | 126 |
// with filepath.Match(). We'll end up supporting more stuff, due to |
| 127 | 127 |
// the fact that we're using regexp, but that's ok - it does no harm. |
| 128 |
+// |
|
| 129 |
+// As per the comment in golangs filepath.Match, on Windows, escaping |
|
| 130 |
+// is disabled. Instead, '\\' is treated as path separator. |
|
| 128 | 131 |
func regexpMatch(pattern, path string) (bool, error) {
|
| 129 | 132 |
regStr := "^" |
| 130 | 133 |
|