From e65e2d104afa8ed5e1846579c9bede7676d5518b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 8 Jun 2015 20:41:39 -0700 Subject: [PATCH 1/2] common: StepDownload can force an extension --- common/step_download.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/common/step_download.go b/common/step_download.go index 8d6378adc..b8bd60b5e 100644 --- a/common/step_download.go +++ b/common/step_download.go @@ -1,6 +1,7 @@ package common import ( + "crypto/sha1" "encoding/hex" "fmt" "log" @@ -36,6 +37,12 @@ type StepDownload struct { // A list of URLs to attempt to download this thing. Url []string + + // Extension is the extension to force for the file that is downloaded. + // Some systems require a certain extension. If this isn't set, the + // extension on the URL is used. Otherwise, this will be forced + // on the downloaded file for every URL. + Extension string } func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction { @@ -60,9 +67,19 @@ func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction { targetPath := s.TargetPath if targetPath == "" { + // Determine a cache key. This is normally just the URL but + // if we force a certain extension we hash the URL and add + // the extension to force it. + cacheKey := url + if s.Extension != "" { + hash := sha1.Sum([]byte(url)) + cacheKey = fmt.Sprintf( + "%s.%s", hex.EncodeToString(hash[:]), s.Extension) + } + log.Printf("Acquiring lock to download: %s", url) - targetPath = cache.Lock(url) - defer cache.Unlock(url) + targetPath = cache.Lock(cacheKey) + defer cache.Unlock(cacheKey) } config := &DownloadConfig{ From 9ea34d4ea85d469272a12dc0ab6fe6837128e382 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 8 Jun 2015 20:42:16 -0700 Subject: [PATCH 2/2] virtualbox/iso: force iso extension for downloads --- builder/virtualbox/iso/builder.go | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index d095eae2d..b6ca982fd 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -230,6 +230,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Description: "ISO", ResultKey: "iso_path", Url: b.config.ISOUrls, + Extension: "iso", }, &vboxcommon.StepOutputDir{ Force: b.config.PackerForce,