diff --git a/cmd/syncthing/upgrade_supported.go b/cmd/syncthing/upgrade_supported.go index 6b09f8533..c7f70c57f 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 1be907a33..ec21f44e4 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 12421bfb7..90610133f 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", ".*"}, }