Merge pull request #5632 from VladRassokhin/do-not-donwload-twice

Do not re-download iso multiple times from different urls
pull/5656/head
SwampDragons 8 years ago committed by GitHub
commit 72afc2eab3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -61,10 +61,12 @@ func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction {
ui.Say(fmt.Sprintf("Downloading or copying %s", s.Description))
var finalPath string
for _, url := range s.Url {
ui.Message(fmt.Sprintf("Downloading or copying: %s", url))
// First try to use any already downloaded file
// If it fails, proceed to regualar download logic
var downloadConfigs = make([]*DownloadConfig, len(s.Url))
var finalPath string
for i, url := range s.Url {
targetPath := s.TargetPath
if targetPath == "" {
// Determine a cache key. This is normally just the URL but
@ -90,19 +92,34 @@ func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction {
Checksum: checksum,
UserAgent: "Packer",
}
downloadConfigs[i] = config
path, err, retry := s.download(config, state)
if err != nil {
ui.Message(fmt.Sprintf("Error downloading: %s", err))
if match, _ := NewDownloadClient(config).VerifyChecksum(config.TargetPath); match {
ui.Message(fmt.Sprintf("Found already downloaded, initial checksum matched, no download needed: %s", url))
finalPath = config.TargetPath
break
}
}
if !retry {
return multistep.ActionHalt
}
if finalPath == "" {
for i, url := range s.Url {
ui.Message(fmt.Sprintf("Downloading or copying: %s", url))
if err == nil {
finalPath = path
break
config := downloadConfigs[i]
path, err, retry := s.download(config, state)
if err != nil {
ui.Message(fmt.Sprintf("Error downloading: %s", err))
}
if !retry {
return multistep.ActionHalt
}
if err == nil {
finalPath = path
break
}
}
}

Loading…
Cancel
Save