internal: check error before deferring file Close()

If there is an error, file will be `nil`. We should check the returned error before deferring file `Close()`.
This commit is contained in:
Emil Hessman
2017-08-13 19:28:13 +02:00
parent a0966e1d1d
commit c2ff7150aa
3 changed files with 3 additions and 4 deletions
+1 -2
View File
@@ -243,11 +243,10 @@ func (node Node) createFileAt(ctx context.Context, path string, repo Repository,
}
f, err := fs.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
defer f.Close()
if err != nil {
return errors.Wrap(err, "OpenFile")
}
defer f.Close()
var buf []byte
for _, id := range node.Content {