summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Borg <jakob@nym.se>2014-06-16 16:18:19 +0200
committerJakob Borg <jakob@nym.se>2014-06-16 16:19:14 +0200
commit874d6760d403911054806646ef9d1d16fa0163b1 (patch)
tree301410b114871508dad7b94bcc6a6591bb5099a0
parent26ebbee8775251772b6eacce8de48bf9c7bf5b56 (diff)
Handle .stignore correctly on Windows (fixes #369)
-rw-r--r--cmd/syncthing/upgrade_supported.go2
-rw-r--r--scanner/walk.go12
-rw-r--r--scanner/walk_test.go4
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", ".*"},
}