lib/scanner: Check ignore patterns before reporting error (fixes #5397) (#5398)

This commit is contained in:
Simon Frei 2018-12-21 12:08:15 +01:00 committed by Jakob Borg
parent fc81e2b3d7
commit 99c9d65ddf
2 changed files with 15 additions and 14 deletions

View File

@ -215,18 +215,14 @@ func (w *walker) walkAndHashFiles(ctx context.Context, toHashChan chan<- protoco
skip = fs.SkipDir
}
if err != nil {
w.handleError(ctx, "scan", path, err, finishedChan)
if !utf8.ValidString(path) {
w.handleError(ctx, "scan", path, errUTF8Invalid, finishedChan)
return skip
}
if path == "." {
return nil
}
if fs.IsTemporary(path) {
l.Debugln("temporary:", path)
if info.IsRegular() && info.ModTime().Add(w.TempLifetime).Before(now) {
l.Debugln("temporary:", path, "err:", err)
if err == nil && info.IsRegular() && info.ModTime().Add(w.TempLifetime).Before(now) {
w.Filesystem.Remove(path)
l.Debugln("removing temporary:", path, info.ModTime())
}
@ -238,15 +234,10 @@ func (w *walker) walkAndHashFiles(ctx context.Context, toHashChan chan<- protoco
return skip
}
if !utf8.ValidString(path) {
w.handleError(ctx, "scan", path, errUTF8Invalid, finishedChan)
return skip
}
if w.Matcher.Match(path).IsIgnored() {
l.Debugln("ignored (patterns):", path)
// Only descend if matcher says so and the current file is not a symlink.
if w.Matcher.SkipIgnoredDirs() || info.IsSymlink() {
if err != nil || w.Matcher.SkipIgnoredDirs() || info.IsSymlink() {
return skip
}
// If the parent wasn't ignored already, set this path as the "highest" ignored parent
@ -256,6 +247,15 @@ func (w *walker) walkAndHashFiles(ctx context.Context, toHashChan chan<- protoco
return nil
}
if err != nil {
w.handleError(ctx, "scan", path, err, finishedChan)
return skip
}
if path == "." {
return nil
}
if ignoredParent == "" {
// parent isn't ignored, nothing special
return w.handleItem(ctx, path, toHashChan, finishedChan, skip)

View File

@ -252,6 +252,7 @@ func TestNormalization(t *testing.T) {
func TestIssue1507(t *testing.T) {
w := &walker{}
w.Matcher = ignore.New(w.Filesystem)
h := make(chan protocol.FileInfo, 100)
f := make(chan ScanResult, 100)
fn := w.walkAndHashFiles(context.TODO(), h, f)