Bläddra i källkod

Revert and replace 31d95ac, 65acc7c, 87780a5

Audrius Butkevicius 11 år sedan
förälder
incheckning
ade437d625
4 ändrade filer med 12 tillägg och 11 borttagningar
  1. 4 4
      internal/ignore/ignore.go
  2. 1 1
      internal/model/model.go
  3. 5 4
      internal/scanner/walk.go
  4. 2 2
      internal/scanner/walk_test.go

+ 4 - 4
internal/ignore/ignore.go

@@ -120,13 +120,13 @@ func (m *Matcher) Match(file string) (result bool) {
 
 func loadIgnoreFile(file string, seen map[string]bool) (*Matcher, error) {
 	if seen[file] {
-		return &Matcher{}, fmt.Errorf("Multiple include of ignore file %q", file)
+		return nil, fmt.Errorf("Multiple include of ignore file %q", file)
 	}
 	seen[file] = true
 
 	fd, err := os.Open(file)
 	if err != nil {
-		return &Matcher{}, err
+		return nil, err
 	}
 	defer fd.Close()
 
@@ -134,7 +134,7 @@ func loadIgnoreFile(file string, seen map[string]bool) (*Matcher, error) {
 }
 
 func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) (*Matcher, error) {
-	exps := Matcher{}
+	var exps Matcher
 
 	addPattern := func(line string) error {
 		include := true
@@ -214,7 +214,7 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) (*M
 			}
 		}
 		if err != nil {
-			return &exps, err
+			return nil, err
 		}
 	}
 

+ 1 - 1
internal/model/model.go

@@ -1017,7 +1017,7 @@ func (m *Model) ScanFolderSub(folder, sub string) error {
 	w := &scanner.Walker{
 		Dir:          dir,
 		Sub:          sub,
-		Ignores:      ignores,
+		Matcher:      ignores,
 		BlockSize:    protocol.BlockSize,
 		TempNamer:    defTempNamer,
 		CurrentFiler: cFiler{m, folder},

+ 5 - 4
internal/scanner/walk.go

@@ -35,8 +35,8 @@ type Walker struct {
 	Sub string
 	// BlockSize controls the size of the block used when hashing.
 	BlockSize int
-	// List of patterns to ignore
-	Ignores *ignore.Matcher
+	// If Matcher is not nil, it is used to identify files to ignore which were specified by the user.
+	Matcher *ignore.Matcher
 	// If TempNamer is not nil, it is used to ignore tempory files when walking.
 	TempNamer TempNamer
 	// If CurrentFiler is not nil, it is queried for the current file before rescanning.
@@ -63,7 +63,7 @@ type CurrentFiler interface {
 // file system. Files are blockwise hashed.
 func (w *Walker) Walk() (chan protocol.FileInfo, error) {
 	if debug {
-		l.Debugln("Walk", w.Dir, w.Sub, w.BlockSize, w.Ignores)
+		l.Debugln("Walk", w.Dir, w.Sub, w.BlockSize, w.Matcher)
 	}
 
 	err := checkDir(w.Dir)
@@ -113,7 +113,8 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun
 			return nil
 		}
 
-		if sn := filepath.Base(rn); sn == ".stignore" || sn == ".stversions" || sn == ".stfolder" || w.Ignores.Match(rn) {
+		if sn := filepath.Base(rn); sn == ".stignore" || sn == ".stversions" ||
+			sn == ".stfolder" || (w.Matcher != nil && w.Matcher.Match(rn)) {
 			// An ignored file
 			if debug {
 				l.Debugln("ignored:", rn)

+ 2 - 2
internal/scanner/walk_test.go

@@ -67,7 +67,7 @@ func TestWalkSub(t *testing.T) {
 		Dir:       "testdata",
 		Sub:       "dir2",
 		BlockSize: 128 * 1024,
-		Ignores:   ignores,
+		Matcher:   ignores,
 	}
 	fchan, err := w.Walk()
 	var files []protocol.FileInfo
@@ -102,7 +102,7 @@ func TestWalk(t *testing.T) {
 	w := Walker{
 		Dir:       "testdata",
 		BlockSize: 128 * 1024,
-		Ignores:   ignores,
+		Matcher:   ignores,
 	}
 
 	fchan, err := w.Walk()