Merge pull request #5632 from VladRassokhin/do-not-donwload-twice
Do not re-download iso multiple times from different urls
This commit is contained in:
commit
72afc2eab3
|
@ -61,10 +61,12 @@ func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
|
||||||
ui.Say(fmt.Sprintf("Downloading or copying %s", s.Description))
|
ui.Say(fmt.Sprintf("Downloading or copying %s", s.Description))
|
||||||
|
|
||||||
var finalPath string
|
// First try to use any already downloaded file
|
||||||
for _, url := range s.Url {
|
// If it fails, proceed to regualar download logic
|
||||||
ui.Message(fmt.Sprintf("Downloading or copying: %s", url))
|
|
||||||
|
|
||||||
|
var downloadConfigs = make([]*DownloadConfig, len(s.Url))
|
||||||
|
var finalPath string
|
||||||
|
for i, url := range s.Url {
|
||||||
targetPath := s.TargetPath
|
targetPath := s.TargetPath
|
||||||
if targetPath == "" {
|
if targetPath == "" {
|
||||||
// Determine a cache key. This is normally just the URL but
|
// Determine a cache key. This is normally just the URL but
|
||||||
|
@ -90,6 +92,20 @@ func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
Checksum: checksum,
|
Checksum: checksum,
|
||||||
UserAgent: "Packer",
|
UserAgent: "Packer",
|
||||||
}
|
}
|
||||||
|
downloadConfigs[i] = config
|
||||||
|
|
||||||
|
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 finalPath == "" {
|
||||||
|
for i, url := range s.Url {
|
||||||
|
ui.Message(fmt.Sprintf("Downloading or copying: %s", url))
|
||||||
|
|
||||||
|
config := downloadConfigs[i]
|
||||||
|
|
||||||
path, err, retry := s.download(config, state)
|
path, err, retry := s.download(config, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -105,6 +121,7 @@ func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if finalPath == "" {
|
if finalPath == "" {
|
||||||
err := fmt.Errorf("%s download failed.", s.Description)
|
err := fmt.Errorf("%s download failed.", s.Description)
|
||||||
|
|
Loading…
Reference in New Issue