Skip to content

Commit 461228a

Browse files
cfergeaugbraad
authored andcommitted
Issue #406 download: Cleanup partially downloaded file on failures
If download fail, use defer() in order to remove the partially downloaded file. This is related to #406
1 parent 3e98ed4 commit 461228a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkg/download/download.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ func Download(uri, destination string) (string, error) {
1515
if err != nil {
1616
return "", errors.Newf("Not able to get response from %s: %v", uri, err)
1717
}
18+
defer func() {
19+
if err != nil {
20+
os.Remove(destination)
21+
}
22+
}()
1823
resp := client.Do(req)
1924
// check for errors
2025
if err := resp.Err(); err != nil {

0 commit comments

Comments
 (0)