Browse Source

Handle .stignore correctly on Windows (fixes #369)

Jakob Borg 11 years ago
parent
commit
874d6760d4
3 changed files with 11 additions and 7 deletions
  1. 1 1
      cmd/syncthing/upgrade_supported.go
  2. 8 4
      scanner/walk.go
  3. 2 2
      scanner/walk_test.go

+ 1 - 1
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
 

+ 8 - 4
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
 				}

+ 2 - 2
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", ".*"},
 	}