From 5fb45262d1d669b177bf318c0db10cf35ea2a720 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 6 Jan 2025 14:05:27 +0000 Subject: [PATCH] releasesjson: Always remove unpacked archive As mentioned in https://github.com/hashicorp/hc-install/issues/145 we never reuse the archive and so it makes sense to *always* remove it rather then collect it for removal by end-user via Remove() method. --- internal/releasesjson/downloader.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/releasesjson/downloader.go b/internal/releasesjson/downloader.go index 708915e..63c8312 100644 --- a/internal/releasesjson/downloader.go +++ b/internal/releasesjson/downloader.go @@ -100,11 +100,17 @@ func (d *Downloader) DownloadAndUnpack(ctx context.Context, pv *ProductVersion, if err != nil { return nil, err } - defer pkgFile.Close() - pkgFilePath, err := filepath.Abs(pkgFile.Name()) + defer func() { + filePath := pkgFile.Name() + defer pkgFile.Close() + err = os.Remove(filePath) + if err != nil { + d.Logger.Printf("failed to delete unpacked archive at %s: %s", filePath, err) + } + d.Logger.Printf("deleted unpacked archive at %s", filePath) + }() up = &UnpackedProduct{} - up.PathsToRemove = append(up.PathsToRemove, pkgFilePath) d.Logger.Printf("copying %q (%d bytes) to %s", pb.Filename, expectedSize, pkgFile.Name())