From f5fa602482a396507430317499d5c71b3c91ba6a Mon Sep 17 00:00:00 2001 From: George Armhold Date: Thu, 26 Oct 2017 13:53:31 -0400 Subject: [PATCH] detect and return error from file Close() in Node.createFileAt() gh-1385 --- internal/restic/node.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/restic/node.go b/internal/restic/node.go index 0ae773e98..f191b5131 100644 --- a/internal/restic/node.go +++ b/internal/restic/node.go @@ -253,8 +253,26 @@ func (node Node) createFileAt(ctx context.Context, path string, repo Repository, if err != nil { return errors.Wrap(err, "OpenFile") } - defer f.Close() + err = node.writeNodeContent(ctx, repo, f) + closeErr := f.Close() + + if err != nil { + return err + } + + if closeErr != nil { + return errors.Wrap(closeErr, "Close") + } + + if node.Links > 1 { + idx.Add(node.Inode, node.DeviceID, path) + } + + return nil +} + +func (node Node) writeNodeContent(ctx context.Context, repo Repository, f *os.File) (error) { var buf []byte for _, id := range node.Content { size, err := repo.LookupBlobSize(id, DataBlob) @@ -279,10 +297,6 @@ func (node Node) createFileAt(ctx context.Context, path string, repo Repository, } } - if node.Links > 1 { - idx.Add(node.Inode, node.DeviceID, path) - } - return nil }