From 747cb00cdc5f9667c91df343f02c444661b220d7 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Wed, 10 Apr 2024 12:12:11 -0400 Subject: [PATCH] packer: remove temp zipfile after installation The zipfile containing the binaries we attempt to install from a remote source is placed in the temporary directory of the host. In general it is wiped automatically by the OS, but in some cases (windows typically), it isn't. To avoid cluttering the temporary directory, we clean-up after ourselves, and remove the temporary zip file that we create when attempting to install a plugin, regardless of it succeeding or not. --- packer/plugin-getter/plugins.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packer/plugin-getter/plugins.go b/packer/plugin-getter/plugins.go index 69c493870..80bae5639 100644 --- a/packer/plugin-getter/plugins.go +++ b/packer/plugin-getter/plugins.go @@ -800,7 +800,11 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error) errs = multierror.Append(errs, err) return nil, errs } - defer tmpFile.Close() + defer func() { + tmpFilePath := tmpFile.Name() + tmpFile.Close() + os.Remove(tmpFilePath) + }() // start fetching binary remoteZipFile, err := getter.Get("zip", GetOptions{ @@ -837,10 +841,6 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error) if err := checksum.Checksummer.Checksum(checksum.Expected, tmpFile); err != nil { err := fmt.Errorf("%w. Is the checksum file correct ? Is the binary file correct ?", err) errs = multierror.Append(errs, err) - log.Printf("%s, truncating the zipfile", err) - if err := tmpFile.Truncate(0); err != nil { - log.Printf("[TRACE] %v", err) - } continue }