mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 11:28:54 +00:00
Merge pull request #1991 from restic/debug-1978
scanner: Use context only for cancellation
This commit is contained in:
commit
0922367308
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 {
|
||||
return ctx.Err()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
}
|
||||
s.Result("", stats)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Scanner) scan(ctx context.Context, stats ScanStats, target string) (ScanStats, error) {
|
||||
if ctx.Err() != nil {
|
||||
return stats, ctx.Err()
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// 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.Bytes += uint64(fi.Size())
|
||||
case fi.Mode().IsDir():
|
||||
if ctx.Err() != nil {
|
||||
return stats, ctx.Err()
|
||||
}
|
||||
|
||||
names, err := readdirnames(s.FS, target)
|
||||
if err != nil {
|
||||
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++
|
||||
}
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return stats, ctx.Err()
|
||||
}
|
||||
s.Result(target, stats)
|
||||
return stats, nil
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ func TestScannerCancel(t *testing.T) {
|
||||
"other": TestFile{Content: "other"},
|
||||
}
|
||||
|
||||
result := ScanStats{Files: 2, Bytes: 6}
|
||||
result := ScanStats{Files: 2, Dirs: 1, Bytes: 6}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@ -319,12 +319,8 @@ func TestScannerCancel(t *testing.T) {
|
||||
}
|
||||
|
||||
err = sc.Scan(ctx, []string{"."})
|
||||
if err == nil {
|
||||
t.Errorf("did not find expected error")
|
||||
}
|
||||
|
||||
if err != context.Canceled {
|
||||
t.Errorf("unexpected error found, want %v, got %v", context.Canceled, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v found", err)
|
||||
}
|
||||
|
||||
if lastStats != result {
|
||||
|
Loading…
Reference in New Issue
Block a user