diff --git a/internal/dump/common.go b/internal/dump/common.go index 5b3d82068..fd74a4a07 100644 --- a/internal/dump/common.go +++ b/internal/dump/common.go @@ -12,6 +12,7 @@ import ( // dumper implements saving node data. type dumper interface { + io.Closer dumpNode(ctx context.Context, node *restic.Node, repo restic.Repository) error } @@ -24,11 +25,13 @@ func writeDump(ctx context.Context, repo restic.Repository, tree *restic.Tree, r rootNode.Path = rootPath err := dumpTree(ctx, repo, rootNode, rootPath, dmp) if err != nil { + dmp.Close() + return err } } - return nil + return dmp.Close() } func dumpTree(ctx context.Context, repo restic.Repository, rootNode *restic.Node, rootPath string, dmp dumper) error { diff --git a/internal/dump/tar.go b/internal/dump/tar.go index c1cd9343f..f9716d152 100644 --- a/internal/dump/tar.go +++ b/internal/dump/tar.go @@ -23,13 +23,10 @@ var _ dumper = tarDumper{} func WriteTar(ctx context.Context, repo restic.Repository, tree *restic.Tree, rootPath string, dst io.Writer) error { dmp := tarDumper{w: tar.NewWriter(dst)} - err := writeDump(ctx, repo, tree, rootPath, dmp, dst) - if err != nil { - dmp.w.Close() - - return err - } + return writeDump(ctx, repo, tree, rootPath, dmp, dst) +} +func (dmp tarDumper) Close() error { return dmp.w.Close() } diff --git a/internal/dump/zip.go b/internal/dump/zip.go index f98afa4a0..f1e779d8e 100644 --- a/internal/dump/zip.go +++ b/internal/dump/zip.go @@ -21,13 +21,10 @@ var _ dumper = zipDumper{} func WriteZip(ctx context.Context, repo restic.Repository, tree *restic.Tree, rootPath string, dst io.Writer) error { dmp := zipDumper{w: zip.NewWriter(dst)} - err := writeDump(ctx, repo, tree, rootPath, dmp, dst) - if err != nil { - dmp.w.Close() - - return err - } + return writeDump(ctx, repo, tree, rootPath, dmp, dst) +} +func (dmp zipDumper) Close() error { return dmp.w.Close() }