Skip to content

Commit

Permalink
Revert "fix: close file without defer"
Browse files Browse the repository at this point in the history
This reverts commit 8d1c45f.
  • Loading branch information
juev committed Dec 11, 2023
1 parent 23f722d commit 6b8b377
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions utils/utils.go
Expand Up @@ -44,27 +44,22 @@ func DownloadWithProgress(url string, tarName string, destFolder string) (err er
return fmt.Errorf("%s returned status code %d", url, resp.StatusCode)
}

f, err := os.OpenFile(destTarPath, os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return err
}
f, _ := os.OpenFile(destTarPath, os.O_CREATE|os.O_WRONLY, 0o644)
defer func(f *os.File) {
if err = f.Close(); err != nil {
color.Errorln("==> [Error]: failed close file", err.Error())
}
}(f)

bar := progressbar.DefaultBytes(
resp.ContentLength,
"Downloading",
)
_, err = io.Copy(io.MultiWriter(f, bar), resp.Body)
if err != nil {
if err := f.Close(); err != nil {
color.Errorln("==> [Error]: failed close file", err.Error())
}
return err
}

if err = f.Close(); err != nil {
color.Errorln("==> [Error]: failed close file", err.Error())
}

return nil
}

Expand Down

0 comments on commit 6b8b377

Please sign in to comment.