diff --git a/internal/restic/node.go b/internal/restic/node.go index c9c68cbee..e23d39f1b 100644 --- a/internal/restic/node.go +++ b/internal/restic/node.go @@ -1,7 +1,6 @@ package restic import ( - "context" "encoding/json" "fmt" "os" @@ -188,7 +187,7 @@ func (node Node) GetExtendedAttribute(a string) []byte { } // NodeCreateAt creates the node at the given path but does NOT restore node meta data. -func NodeCreateAt(ctx context.Context, node *Node, path string, repo BlobLoader) error { +func NodeCreateAt(node *Node, path string) error { debug.Log("create node %v at %v", node.Name, path) switch node.Type { @@ -197,7 +196,7 @@ func NodeCreateAt(ctx context.Context, node *Node, path string, repo BlobLoader) return err } case "file": - if err := nodeCreateFileAt(ctx, node, path, repo); err != nil { + if err := nodeCreateFileAt(path); err != nil { return err } case "symlink": @@ -310,38 +309,14 @@ func nodeCreateDirAt(node *Node, path string) error { return nil } -func nodeCreateFileAt(ctx context.Context, node *Node, path string, repo BlobLoader) error { +func nodeCreateFileAt(path string) error { f, err := fs.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600) if err != nil { return errors.WithStack(err) } - err = nodeWriteNodeContent(ctx, node, repo, f) - closeErr := f.Close() - - if err != nil { - return err - } - - if closeErr != nil { - return errors.WithStack(closeErr) - } - - return nil -} - -func nodeWriteNodeContent(ctx context.Context, node *Node, repo BlobLoader, f *os.File) error { - var buf []byte - for _, id := range node.Content { - buf, err := repo.LoadBlob(ctx, DataBlob, id, buf) - if err != nil { - return err - } - - _, err = f.Write(buf) - if err != nil { - return errors.WithStack(err) - } + if err := f.Close(); err != nil { + return errors.WithStack(err) } return nil diff --git a/internal/restic/node_test.go b/internal/restic/node_test.go index 7258b5429..075dd5cc5 100644 --- a/internal/restic/node_test.go +++ b/internal/restic/node_test.go @@ -1,7 +1,6 @@ package restic import ( - "context" "encoding/json" "fmt" "os" @@ -245,7 +244,7 @@ func TestNodeRestoreAt(t *testing.T) { } else { nodePath = filepath.Join(tempdir, test.Name) } - rtest.OK(t, NodeCreateAt(context.TODO(), &test, nodePath, nil)) + rtest.OK(t, NodeCreateAt(&test, nodePath)) rtest.OK(t, NodeRestoreMetadata(&test, nodePath, func(msg string) { rtest.OK(t, fmt.Errorf("Warning triggered for path: %s: %s", nodePath, msg)) })) fi, err := os.Lstat(nodePath) diff --git a/internal/restorer/restorer.go b/internal/restorer/restorer.go index 31157c979..83644c7ac 100644 --- a/internal/restorer/restorer.go +++ b/internal/restorer/restorer.go @@ -265,14 +265,14 @@ func (res *Restorer) traverseTreeInner(ctx context.Context, target, location str return filenames, hasRestored, nil } -func (res *Restorer) restoreNodeTo(ctx context.Context, node *restic.Node, target, location string) error { +func (res *Restorer) restoreNodeTo(node *restic.Node, target, location string) error { if !res.opts.DryRun { debug.Log("restoreNode %v %v %v", node.Name, target, location) if err := fs.Remove(target); err != nil && !errors.Is(err, os.ErrNotExist) { return errors.Wrap(err, "RemoveNode") } - err := restic.NodeCreateAt(ctx, node, target, res.repo) + err := restic.NodeCreateAt(node, target) if err != nil { debug.Log("node.CreateAt(%s) error %v", target, err) return err @@ -435,7 +435,7 @@ func (res *Restorer) RestoreTo(ctx context.Context, dst string) (uint64, error) debug.Log("second pass, visitNode: restore node %q", location) if node.Type != "file" { _, err := res.withOverwriteCheck(ctx, node, target, location, false, nil, func(_ bool, _ *fileState) error { - return res.restoreNodeTo(ctx, node, target, location) + return res.restoreNodeTo(node, target, location) }) return err }