archiver: Let saveTree report a canceled context as an error

If the context was canceled then saveTree might receive a treeID or not
depending on the timing. This could cause saveTree to incorrectly return
a nil treeID as valid. Fix this always returning an error when the
context was canceled in the meantime.
This commit is contained in:
Michael Eischer 2020-12-13 20:06:44 +01:00
parent 736e964317
commit fc60b560ba
1 changed files with 4 additions and 0 deletions

View File

@ -178,6 +178,10 @@ func (arch *Archiver) saveTree(ctx context.Context, t *restic.Tree) (restic.ID,
s.TreeBlobs++
s.TreeSize += uint64(len(buf))
}
// The context was canceled in the meantime, res.ID() might be invalid
if ctx.Err() != nil {
return restic.ID{}, s, ctx.Err()
}
return res.ID(), s, nil
}