Merge pull request #854 from AudriusButkevicius/nils

Revert and replace 31d95ac, 65acc7c, 87780a5
This commit is contained in:
Audrius Butkevicius 2014-10-15 08:24:19 +01:00
commit aaf625c624
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) {
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
}
}

View File

@ -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},

View File

@ -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)

View File

@ -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()