Skip to content

Commit 03dbe70

Browse files
committed
Always delete downloader temporary data file
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]>
1 parent a07b7f9 commit 03dbe70

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

pkg/downloader/downloader.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,6 @@ func downloadHTTP(ctx context.Context, localPath, lastModified, contentType, url
599599
}
600600
logrus.Debugf("downloading %q into %q", url, localPath)
601601

602-
localPathTmp := perProcessTempfile(localPath)
603-
fileWriter, err := os.Create(localPathTmp)
604-
if err != nil {
605-
return err
606-
}
607-
defer fileWriter.Close()
608-
609602
resp, err := httpclientutil.Get(ctx, http.DefaultClient, url)
610603
if err != nil {
611604
return err
@@ -631,6 +624,14 @@ func downloadHTTP(ctx context.Context, localPath, lastModified, contentType, url
631624
hideBar(bar)
632625
}
633626

627+
localPathTmp := perProcessTempfile(localPath)
628+
fileWriter, err := os.Create(localPathTmp)
629+
if err != nil {
630+
return err
631+
}
632+
defer fileWriter.Close()
633+
defer os.RemoveAll(localPathTmp)
634+
634635
writers := []io.Writer{fileWriter}
635636
var digester digest.Digester
636637
if expectedDigest != "" {

0 commit comments

Comments
 (0)