Skip to content

Commit

Permalink
Always delete downloader temporary data file
Browse files Browse the repository at this point in the history
If the download failed, the temporary data file (data.tmp.pid) was not
deleted. Ensure it is delete in all cases.

Also move the creation of the temporary file right before we need it.
The chance that creating a temporary file will fail is practically zero
so there is no need to do this upfront. This makes the code easier to
follow and maintain.

Signed-off-by: Nir Soffer <[email protected]>
  • Loading branch information
nirs committed Oct 11, 2024
1 parent a07b7f9 commit 03dbe70
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,6 @@ func downloadHTTP(ctx context.Context, localPath, lastModified, contentType, url
}
logrus.Debugf("downloading %q into %q", url, localPath)

localPathTmp := perProcessTempfile(localPath)
fileWriter, err := os.Create(localPathTmp)
if err != nil {
return err
}
defer fileWriter.Close()

resp, err := httpclientutil.Get(ctx, http.DefaultClient, url)
if err != nil {
return err
Expand All @@ -631,6 +624,14 @@ func downloadHTTP(ctx context.Context, localPath, lastModified, contentType, url
hideBar(bar)
}

localPathTmp := perProcessTempfile(localPath)
fileWriter, err := os.Create(localPathTmp)
if err != nil {
return err
}
defer fileWriter.Close()
defer os.RemoveAll(localPathTmp)

writers := []io.Writer{fileWriter}
var digester digest.Digester
if expectedDigest != "" {
Expand Down

0 comments on commit 03dbe70

Please sign in to comment.