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.
pull/12964/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent 61199aed0d
commit 747cb00cdc

@ -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
}

Loading…
Cancel
Save