forked from TrueCloudLab/restic
Deduplicate dumper closing logic
This commit is contained in:
parent
e136dd8696
commit
83b10dbb12
3 changed files with 10 additions and 13 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
// dumper implements saving node data.
|
// dumper implements saving node data.
|
||||||
type dumper interface {
|
type dumper interface {
|
||||||
|
io.Closer
|
||||||
dumpNode(ctx context.Context, node *restic.Node, repo restic.Repository) error
|
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
|
rootNode.Path = rootPath
|
||||||
err := dumpTree(ctx, repo, rootNode, rootPath, dmp)
|
err := dumpTree(ctx, repo, rootNode, rootPath, dmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
dmp.Close()
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return dmp.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpTree(ctx context.Context, repo restic.Repository, rootNode *restic.Node, rootPath string, dmp dumper) error {
|
func dumpTree(ctx context.Context, repo restic.Repository, rootNode *restic.Node, rootPath string, dmp dumper) error {
|
||||||
|
|
|
@ -23,13 +23,10 @@ var _ dumper = tarDumper{}
|
||||||
func WriteTar(ctx context.Context, repo restic.Repository, tree *restic.Tree, rootPath string, dst io.Writer) error {
|
func WriteTar(ctx context.Context, repo restic.Repository, tree *restic.Tree, rootPath string, dst io.Writer) error {
|
||||||
dmp := tarDumper{w: tar.NewWriter(dst)}
|
dmp := tarDumper{w: tar.NewWriter(dst)}
|
||||||
|
|
||||||
err := writeDump(ctx, repo, tree, rootPath, dmp, dst)
|
return writeDump(ctx, repo, tree, rootPath, dmp, dst)
|
||||||
if err != nil {
|
}
|
||||||
dmp.w.Close()
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
func (dmp tarDumper) Close() error {
|
||||||
return dmp.w.Close()
|
return dmp.w.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,10 @@ var _ dumper = zipDumper{}
|
||||||
func WriteZip(ctx context.Context, repo restic.Repository, tree *restic.Tree, rootPath string, dst io.Writer) error {
|
func WriteZip(ctx context.Context, repo restic.Repository, tree *restic.Tree, rootPath string, dst io.Writer) error {
|
||||||
dmp := zipDumper{w: zip.NewWriter(dst)}
|
dmp := zipDumper{w: zip.NewWriter(dst)}
|
||||||
|
|
||||||
err := writeDump(ctx, repo, tree, rootPath, dmp, dst)
|
return writeDump(ctx, repo, tree, rootPath, dmp, dst)
|
||||||
if err != nil {
|
}
|
||||||
dmp.w.Close()
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
func (dmp zipDumper) Close() error {
|
||||||
return dmp.w.Close()
|
return dmp.w.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue