Commit f6f9cca7 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge pull request #2189 from mitchellh/b-download-extension

common: StepDownload can force an extension
parents b31534d5 9ea34d4e
...@@ -230,6 +230,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -230,6 +230,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Description: "ISO", Description: "ISO",
ResultKey: "iso_path", ResultKey: "iso_path",
Url: b.config.ISOUrls, Url: b.config.ISOUrls,
Extension: "iso",
}, },
&vboxcommon.StepOutputDir{ &vboxcommon.StepOutputDir{
Force: b.config.PackerForce, Force: b.config.PackerForce,
......
package common package common
import ( import (
"crypto/sha1"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"log" "log"
...@@ -36,6 +37,12 @@ type StepDownload struct { ...@@ -36,6 +37,12 @@ type StepDownload struct {
// A list of URLs to attempt to download this thing. // A list of URLs to attempt to download this thing.
Url []string 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 { func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction {
...@@ -60,9 +67,19 @@ 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 targetPath := s.TargetPath
if 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) log.Printf("Acquiring lock to download: %s", url)
targetPath = cache.Lock(url) targetPath = cache.Lock(cacheKey)
defer cache.Unlock(url) defer cache.Unlock(cacheKey)
} }
config := &DownloadConfig{ config := &DownloadConfig{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment