From ade437d6257e63243aade8105c61c9bb95cc1ba6 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Tue, 14 Oct 2014 21:30:00 +0100 Subject: [PATCH] Revert and replace 31d95ac, 65acc7c, 87780a5 --- internal/ignore/ignore.go | 8 ++++---- internal/model/model.go | 2 +- internal/scanner/walk.go | 9 +++++---- internal/scanner/walk_test.go | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/internal/ignore/ignore.go b/internal/ignore/ignore.go index df8a4239e..39ab7d21e 100644 --- a/internal/ignore/ignore.go +++ b/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 } } diff --git a/internal/model/model.go b/internal/model/model.go index b88dd3b9a..e70aefe15 100644 --- a/internal/model/model.go +++ b/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}, diff --git a/internal/scanner/walk.go b/internal/scanner/walk.go index 1a1d7897a..c234b2aeb 100644 --- a/internal/scanner/walk.go +++ b/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) diff --git a/internal/scanner/walk_test.go b/internal/scanner/walk_test.go index 084aaabd1..d7e367dc3 100644 --- a/internal/scanner/walk_test.go +++ b/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()