1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-24 16:54:00 +00:00

detect and return error from file Close() in Node.createFileAt()

gh-1385
This commit is contained in:
George Armhold 2017-10-26 13:53:31 -04:00
parent bcdebfb84e
commit f5fa602482

View file

@ -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
}