lib/scanner: Do not drop all not-exist-errors and debug logging (#7675)

This commit is contained in:
Simon Frei
2021-05-15 11:51:35 +02:00
committed by GitHub
parent 0d054f9b64
commit 93a02c677e
+21 -18
View File
@@ -109,7 +109,7 @@ type walker struct {
// Walk returns the list of files found in the local folder by scanning the // Walk returns the list of files found in the local folder by scanning the
// file system. Files are blockwise hashed. // file system. Files are blockwise hashed.
func (w *walker) walk(ctx context.Context) chan ScanResult { func (w *walker) walk(ctx context.Context) chan ScanResult {
l.Debugln("Walk", w.Subs, w.Matcher) l.Debugln(w, "Walk", w.Subs, w.Matcher)
toHashChan := make(chan protocol.FileInfo) toHashChan := make(chan protocol.FileInfo)
finishedChan := make(chan ScanResult) finishedChan := make(chan ScanResult)
@@ -162,13 +162,13 @@ func (w *walker) walk(ctx context.Context) chan ScanResult {
for { for {
select { select {
case <-done: case <-done:
l.Debugln("Walk progress done", w.Folder, w.Subs, w.Matcher) l.Debugln(w, "Walk progress done", w.Folder, w.Subs, w.Matcher)
ticker.Stop() ticker.Stop()
return return
case <-ticker.C: case <-ticker.C:
current := progress.Total() current := progress.Total()
rate := progress.Rate() rate := progress.Rate()
l.Debugf("Walk %s %s current progress %d/%d at %.01f MiB/s (%d%%)", w.Folder, w.Subs, current, total, rate/1024/1024, current*100/total) l.Debugf("%v: Walk %s %s current progress %d/%d at %.01f MiB/s (%d%%)", w, w.Folder, w.Subs, current, total, rate/1024/1024, current*100/total)
w.EventLogger.Log(events.FolderScanProgress, map[string]interface{}{ w.EventLogger.Log(events.FolderScanProgress, map[string]interface{}{
"folder": w.Folder, "folder": w.Folder,
"current": current, "current": current,
@@ -184,7 +184,7 @@ func (w *walker) walk(ctx context.Context) chan ScanResult {
loop: loop:
for _, file := range filesToHash { for _, file := range filesToHash {
l.Debugln("real to hash:", file.Name) l.Debugln(w, "real to hash:", file.Name)
select { select {
case realToHashChan <- file: case realToHashChan <- file:
case <-ctx.Done(): case <-ctx.Done():
@@ -198,7 +198,7 @@ func (w *walker) walk(ctx context.Context) chan ScanResult {
} }
func (w *walker) walkWithoutHashing(ctx context.Context) chan ScanResult { func (w *walker) walkWithoutHashing(ctx context.Context) chan ScanResult {
l.Debugln("Walk without hashing", w.Subs, w.Matcher) l.Debugln(w, "Walk without hashing", w.Subs, w.Matcher)
toHashChan := make(chan protocol.FileInfo) toHashChan := make(chan protocol.FileInfo)
finishedChan := make(chan ScanResult) finishedChan := make(chan ScanResult)
@@ -224,7 +224,7 @@ func (w *walker) scan(ctx context.Context, toHashChan chan<- protocol.FileInfo,
} else { } else {
for _, sub := range w.Subs { for _, sub := range w.Subs {
if err := osutil.TraversesSymlink(w.Filesystem, filepath.Dir(sub)); err != nil { if err := osutil.TraversesSymlink(w.Filesystem, filepath.Dir(sub)); err != nil {
l.Debugf("Skip walking %v as it is below a symlink", sub) l.Debugf("%v: Skip walking %v as it is below a symlink", w, sub)
continue continue
} }
w.Filesystem.Walk(sub, hashFiles) w.Filesystem.Walk(sub, hashFiles)
@@ -258,21 +258,21 @@ func (w *walker) walkAndHashFiles(ctx context.Context, toHashChan chan<- protoco
} }
if fs.IsTemporary(path) { if fs.IsTemporary(path) {
l.Debugln("temporary:", path, "err:", err) l.Debugln(w, "temporary:", path, "err:", err)
if err == nil && info.IsRegular() && info.ModTime().Add(w.TempLifetime).Before(now) { if err == nil && info.IsRegular() && info.ModTime().Add(w.TempLifetime).Before(now) {
w.Filesystem.Remove(path) w.Filesystem.Remove(path)
l.Debugln("removing temporary:", path, info.ModTime()) l.Debugln(w, "removing temporary:", path, info.ModTime())
} }
return nil return nil
} }
if fs.IsInternal(path) { if fs.IsInternal(path) {
l.Debugln("ignored (internal):", path) l.Debugln(w, "ignored (internal):", path)
return skip return skip
} }
if w.Matcher.Match(path).IsIgnored() { if w.Matcher.Match(path).IsIgnored() {
l.Debugln("ignored (patterns):", path) l.Debugln(w, "ignored (patterns):", path)
// Only descend if matcher says so and the current file is not a symlink. // Only descend if matcher says so and the current file is not a symlink.
if err != nil || w.Matcher.SkipIgnoredDirs() || info.IsSymlink() { if err != nil || w.Matcher.SkipIgnoredDirs() || info.IsSymlink() {
return skip return skip
@@ -285,7 +285,11 @@ func (w *walker) walkAndHashFiles(ctx context.Context, toHashChan chan<- protoco
} }
if err != nil { if err != nil {
// No need reporting errors for files that don't exist (e.g. scan
// due to filesystem watcher)
if !fs.IsNotExist(err) {
handleError(ctx, "scan", path, err, finishedChan) handleError(ctx, "scan", path, err, finishedChan)
}
return skip return skip
} }
@@ -384,6 +388,7 @@ func (w *walker) walkRegular(ctx context.Context, relPath string, info fs.FileIn
if hasCurFile { if hasCurFile {
if curFile.IsEquivalentOptional(f, w.ModTimeWindow, w.IgnorePerms, true, w.LocalFlags) { if curFile.IsEquivalentOptional(f, w.ModTimeWindow, w.IgnorePerms, true, w.LocalFlags) {
l.Debugln(w, "unchanged:", curFile, info.ModTime().Unix(), info.Mode()&fs.ModePerm)
return nil return nil
} }
if curFile.ShouldConflict() { if curFile.ShouldConflict() {
@@ -394,10 +399,10 @@ func (w *walker) walkRegular(ctx context.Context, relPath string, info fs.FileIn
// conflict. // conflict.
f.Version = f.Version.DropOthers(w.ShortID) f.Version = f.Version.DropOthers(w.ShortID)
} }
l.Debugln("rescan:", curFile, info.ModTime().Unix(), info.Mode()&fs.ModePerm) l.Debugln(w, "rescan:", curFile, info.ModTime().Unix(), info.Mode()&fs.ModePerm)
} }
l.Debugln("to hash:", relPath, f) l.Debugln(w, "to hash:", relPath, f)
select { select {
case toHashChan <- f: case toHashChan <- f:
@@ -417,6 +422,7 @@ func (w *walker) walkDir(ctx context.Context, relPath string, info fs.FileInfo,
if hasCurFile { if hasCurFile {
if curFile.IsEquivalentOptional(f, w.ModTimeWindow, w.IgnorePerms, true, w.LocalFlags) { if curFile.IsEquivalentOptional(f, w.ModTimeWindow, w.IgnorePerms, true, w.LocalFlags) {
l.Debugln(w, "unchanged:", curFile, info.ModTime().Unix(), info.Mode()&fs.ModePerm)
return nil return nil
} }
if curFile.ShouldConflict() { if curFile.ShouldConflict() {
@@ -429,7 +435,7 @@ func (w *walker) walkDir(ctx context.Context, relPath string, info fs.FileInfo,
} }
} }
l.Debugln("dir:", relPath, f) l.Debugln(w, "dir:", relPath, f)
select { select {
case finishedChan <- ScanResult{File: f}: case finishedChan <- ScanResult{File: f}:
@@ -461,6 +467,7 @@ func (w *walker) walkSymlink(ctx context.Context, relPath string, info fs.FileIn
if hasCurFile { if hasCurFile {
if curFile.IsEquivalentOptional(f, w.ModTimeWindow, w.IgnorePerms, true, w.LocalFlags) { if curFile.IsEquivalentOptional(f, w.ModTimeWindow, w.IgnorePerms, true, w.LocalFlags) {
l.Debugln(w, "unchanged:", curFile, info.ModTime().Unix(), info.Mode()&fs.ModePerm)
return nil return nil
} }
if curFile.ShouldConflict() { if curFile.ShouldConflict() {
@@ -473,7 +480,7 @@ func (w *walker) walkSymlink(ctx context.Context, relPath string, info fs.FileIn
} }
} }
l.Debugln("symlink changedb:", relPath, f) l.Debugln(w, "symlink changedb:", relPath, f)
select { select {
case finishedChan <- ScanResult{File: f}: case finishedChan <- ScanResult{File: f}:
@@ -557,10 +564,6 @@ func (w *walker) updateFileInfo(file, curFile protocol.FileInfo) protocol.FileIn
} }
func handleError(ctx context.Context, context, path string, err error, finishedChan chan<- ScanResult) { func handleError(ctx context.Context, context, path string, err error, finishedChan chan<- ScanResult) {
// Ignore missing items, as deletions are not handled by the scanner.
if fs.IsNotExist(err) {
return
}
select { select {
case finishedChan <- ScanResult{ case finishedChan <- ScanResult{
Err: fmt.Errorf("%s: %w", context, err), Err: fmt.Errorf("%s: %w", context, err),