1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-24 08:44:52 +00:00

archiver: Don't loose error if background context is canceled

A canceled background context lets the blob/tree/fileSavers exit
without reporting an error. The error handling previously replaced
a 'context canceled' error received by the main backup method with
the error reported by the savers. However, in case of a canceled
background context that error is nil, causing restic to loose the
error and save a snapshot with a nil tree.
This commit is contained in:
Michael Eischer 2020-12-13 20:01:16 +01:00
parent 9c41e4a343
commit 736e964317

View file

@ -803,7 +803,8 @@ func (arch *Archiver) Snapshot(ctx context.Context, targets []string, opts Snaps
t.Kill(nil) t.Kill(nil)
werr := t.Wait() werr := t.Wait()
debug.Log("err is %v, werr is %v", err, werr) debug.Log("err is %v, werr is %v", err, werr)
if err == nil || errors.Cause(err) == context.Canceled { // Use werr when it might contain a more specific error than "context canceled"
if err == nil || (errors.Cause(err) == context.Canceled && werr != nil) {
err = werr err = werr
} }