Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/tfvars/libvirt/cache: Close before renaming #464

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pkg/tfvars/libvirt/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,23 @@ func cacheImage(reader io.Reader, imagePath string) (err error) {
if err != nil {
return err
}
defer file.Close()
closed := false
defer func() {
if !closed {
file.Close()
}
}()

_, err = io.Copy(file, reader)
if err != nil {
return err
}

err = file.Close()
if err != nil {
return err
}
closed = true

return os.Rename(tempPath, imagePath)
}