forked from TrueCloudLab/restic
Merge pull request #1991 from restic/debug-1978
scanner: Use context only for cancellation
This commit is contained in:
commit
0922367308
3 changed files with 17 additions and 19 deletions
12
changelog/unreleased/issue-1978
Normal file
12
changelog/unreleased/issue-1978
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
Bugfix: Do not return an error when the scanner is faster than backup
|
||||||
|
|
||||||
|
When restic makes a backup, there's a background task called "scanner" which
|
||||||
|
collects information on how many files and directories are to be saved, in
|
||||||
|
order to display progress information to the user. When the backup finishes
|
||||||
|
faster than the scanner, it is aborted because the result is not needed any
|
||||||
|
more. This logic contained a bug, where quitting the scanner process was
|
||||||
|
treated as an error, and caused restic to print an unhelpful error message
|
||||||
|
("context canceled").
|
||||||
|
|
||||||
|
https://github.com/restic/restic/issues/1978
|
||||||
|
https://github.com/restic/restic/pull/1991
|
|
@ -52,20 +52,17 @@ func (s *Scanner) Scan(ctx context.Context, targets []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return ctx.Err()
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Err() != nil {
|
|
||||||
return ctx.Err()
|
|
||||||
}
|
|
||||||
s.Result("", stats)
|
s.Result("", stats)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scanner) scan(ctx context.Context, stats ScanStats, target string) (ScanStats, error) {
|
func (s *Scanner) scan(ctx context.Context, stats ScanStats, target string) (ScanStats, error) {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return stats, ctx.Err()
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// exclude files by path before running stat to reduce number of lstat calls
|
// exclude files by path before running stat to reduce number of lstat calls
|
||||||
|
@ -89,10 +86,6 @@ func (s *Scanner) scan(ctx context.Context, stats ScanStats, target string) (Sca
|
||||||
stats.Files++
|
stats.Files++
|
||||||
stats.Bytes += uint64(fi.Size())
|
stats.Bytes += uint64(fi.Size())
|
||||||
case fi.Mode().IsDir():
|
case fi.Mode().IsDir():
|
||||||
if ctx.Err() != nil {
|
|
||||||
return stats, ctx.Err()
|
|
||||||
}
|
|
||||||
|
|
||||||
names, err := readdirnames(s.FS, target)
|
names, err := readdirnames(s.FS, target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stats, s.Error(target, fi, err)
|
return stats, s.Error(target, fi, err)
|
||||||
|
@ -109,9 +102,6 @@ func (s *Scanner) scan(ctx context.Context, stats ScanStats, target string) (Sca
|
||||||
stats.Others++
|
stats.Others++
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Err() != nil {
|
|
||||||
return stats, ctx.Err()
|
|
||||||
}
|
|
||||||
s.Result(target, stats)
|
s.Result(target, stats)
|
||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,7 +289,7 @@ func TestScannerCancel(t *testing.T) {
|
||||||
"other": TestFile{Content: "other"},
|
"other": TestFile{Content: "other"},
|
||||||
}
|
}
|
||||||
|
|
||||||
result := ScanStats{Files: 2, Bytes: 6}
|
result := ScanStats{Files: 2, Dirs: 1, Bytes: 6}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -319,12 +319,8 @@ func TestScannerCancel(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sc.Scan(ctx, []string{"."})
|
err = sc.Scan(ctx, []string{"."})
|
||||||
if err == nil {
|
if err != nil {
|
||||||
t.Errorf("did not find expected error")
|
t.Errorf("unexpected error %v found", err)
|
||||||
}
|
|
||||||
|
|
||||||
if err != context.Canceled {
|
|
||||||
t.Errorf("unexpected error found, want %v, got %v", context.Canceled, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if lastStats != result {
|
if lastStats != result {
|
||||||
|
|
Loading…
Reference in a new issue