Revert and replace 31d95ac, 65acc7c, 87780a5

This commit is contained in:
Audrius Butkevicius 2014-10-14 21:30:00 +01:00
parent 87780a5b7e
commit ade437d625
4 changed files with 12 additions and 11 deletions

View File

@ -120,13 +120,13 @@ func (m *Matcher) Match(file string) (result bool) {
func loadIgnoreFile(file string, seen map[string]bool) (*Matcher, error) { func loadIgnoreFile(file string, seen map[string]bool) (*Matcher, error) {
if seen[file] { 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 seen[file] = true
fd, err := os.Open(file) fd, err := os.Open(file)
if err != nil { if err != nil {
return &Matcher{}, err return nil, err
} }
defer fd.Close() 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) { func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) (*Matcher, error) {
exps := Matcher{} var exps Matcher
addPattern := func(line string) error { addPattern := func(line string) error {
include := true include := true
@ -214,7 +214,7 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) (*M
} }
} }
if err != nil { if err != nil {
return &exps, err return nil, err
} }
} }

View File

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

View File

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

View File

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