diff options
author | Jakob Borg <jakob@nym.se> | 2014-06-16 16:18:19 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-06-16 16:19:14 +0200 |
commit | 874d6760d403911054806646ef9d1d16fa0163b1 (patch) | |
tree | 301410b114871508dad7b94bcc6a6591bb5099a0 | |
parent | 26ebbee8775251772b6eacce8de48bf9c7bf5b56 (diff) |
Handle .stignore correctly on Windows (fixes #369)
-rw-r--r-- | cmd/syncthing/upgrade_supported.go | 2 | ||||
-rw-r--r-- | scanner/walk.go | 12 | ||||
-rw-r--r-- | scanner/walk_test.go | 4 |
3 files changed, 11 insertions, 7 deletions
diff --git a/cmd/syncthing/upgrade_supported.go b/cmd/syncthing/upgrade_supported.go index 6b09f85331..c7f70c57f4 100644 --- a/cmd/syncthing/upgrade_supported.go +++ b/cmd/syncthing/upgrade_supported.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT-style license that can be // found in the LICENSE file. -// +build !solaris +// +build !solaris,!windows package main diff --git a/scanner/walk.go b/scanner/walk.go index 1be907a33a..ec21f44e49 100644 --- a/scanner/walk.go +++ b/scanner/walk.go @@ -7,6 +7,7 @@ package scanner import ( "bytes" "errors" + "fmt" "io/ioutil" "os" "path/filepath" @@ -104,13 +105,15 @@ func (w *Walker) loadIgnoreFiles(dir string, ign map[string][]string) filepath.W } if pn, sn := filepath.Split(rn); sn == w.IgnoreFile { - pn := strings.Trim(pn, "/") + pn := filepath.Clean(pn) + l.Debugf("pn: %q", pn) bs, _ := ioutil.ReadFile(p) lines := bytes.Split(bs, []byte("\n")) var patterns []string for _, line := range lines { - if len(line) > 0 { - patterns = append(patterns, string(line)) + lineStr := strings.TrimSpace(string(line)) + if len(lineStr) > 0 { + patterns = append(patterns, lineStr) } } ign[pn] = patterns @@ -282,8 +285,9 @@ func (w *Walker) cleanTempFile(path string, info os.FileInfo, err error) error { func (w *Walker) ignoreFile(patterns map[string][]string, file string) bool { first, last := filepath.Split(file) for prefix, pats := range patterns { - if len(prefix) == 0 || prefix == first || strings.HasPrefix(first, prefix+"/") { + if prefix == "." || prefix == first || strings.HasPrefix(first, fmt.Sprintf("%s%c", prefix, os.PathSeparator)) { for _, pattern := range pats { + l.Debugf("%q %q", pattern, last) if match, _ := filepath.Match(pattern, last); match { return true } diff --git a/scanner/walk_test.go b/scanner/walk_test.go index 12421bfb7e..90610133f3 100644 --- a/scanner/walk_test.go +++ b/scanner/walk_test.go @@ -22,7 +22,7 @@ var testdata = []struct { } var correctIgnores = map[string][]string{ - "": {".*", "quux"}, + ".": {".*", "quux"}, } func TestWalk(t *testing.T) { @@ -88,7 +88,7 @@ func TestWalkError(t *testing.T) { func TestIgnore(t *testing.T) { var patterns = map[string][]string{ - "": {"t2"}, + ".": {"t2"}, "foo": {"bar", "z*"}, "foo/baz": {"quux", ".*"}, } |