2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-25 12:09:59 +00:00

diff: improve cancelation handling

This commit is contained in:
Michael Eischer 2024-07-31 19:45:33 +02:00
parent ae1cb889dd
commit a639454f28

View File

@ -191,13 +191,13 @@ func (c *Comparer) printDir(ctx context.Context, mode string, stats *DiffStat, b
if node.Type == "dir" { if node.Type == "dir" {
err := c.printDir(ctx, mode, stats, blobs, name, *node.Subtree) err := c.printDir(ctx, mode, stats, blobs, name, *node.Subtree)
if err != nil { if err != nil && err != context.Canceled {
Warnf("error: %v\n", err) Warnf("error: %v\n", err)
} }
} }
} }
return nil return ctx.Err()
} }
func (c *Comparer) collectDir(ctx context.Context, blobs restic.BlobSet, id restic.ID) error { func (c *Comparer) collectDir(ctx context.Context, blobs restic.BlobSet, id restic.ID) error {
@ -216,13 +216,13 @@ func (c *Comparer) collectDir(ctx context.Context, blobs restic.BlobSet, id rest
if node.Type == "dir" { if node.Type == "dir" {
err := c.collectDir(ctx, blobs, *node.Subtree) err := c.collectDir(ctx, blobs, *node.Subtree)
if err != nil { if err != nil && err != context.Canceled {
Warnf("error: %v\n", err) Warnf("error: %v\n", err)
} }
} }
} }
return nil return ctx.Err()
} }
func uniqueNodeNames(tree1, tree2 *restic.Tree) (tree1Nodes, tree2Nodes map[string]*restic.Node, uniqueNames []string) { func uniqueNodeNames(tree1, tree2 *restic.Tree) (tree1Nodes, tree2Nodes map[string]*restic.Node, uniqueNames []string) {
@ -316,7 +316,7 @@ func (c *Comparer) diffTree(ctx context.Context, stats *DiffStatsContainer, pref
} else { } else {
err = c.diffTree(ctx, stats, name, *node1.Subtree, *node2.Subtree) err = c.diffTree(ctx, stats, name, *node1.Subtree, *node2.Subtree)
} }
if err != nil { if err != nil && err != context.Canceled {
Warnf("error: %v\n", err) Warnf("error: %v\n", err)
} }
} }
@ -330,7 +330,7 @@ func (c *Comparer) diffTree(ctx context.Context, stats *DiffStatsContainer, pref
if node1.Type == "dir" { if node1.Type == "dir" {
err := c.printDir(ctx, "-", &stats.Removed, stats.BlobsBefore, prefix, *node1.Subtree) err := c.printDir(ctx, "-", &stats.Removed, stats.BlobsBefore, prefix, *node1.Subtree)
if err != nil { if err != nil && err != context.Canceled {
Warnf("error: %v\n", err) Warnf("error: %v\n", err)
} }
} }
@ -344,14 +344,14 @@ func (c *Comparer) diffTree(ctx context.Context, stats *DiffStatsContainer, pref
if node2.Type == "dir" { if node2.Type == "dir" {
err := c.printDir(ctx, "+", &stats.Added, stats.BlobsAfter, prefix, *node2.Subtree) err := c.printDir(ctx, "+", &stats.Added, stats.BlobsAfter, prefix, *node2.Subtree)
if err != nil { if err != nil && err != context.Canceled {
Warnf("error: %v\n", err) Warnf("error: %v\n", err)
} }
} }
} }
} }
return nil return ctx.Err()
} }
func runDiff(ctx context.Context, opts DiffOptions, gopts GlobalOptions, args []string) error { func runDiff(ctx context.Context, opts DiffOptions, gopts GlobalOptions, args []string) error {