From 71664cb34eedd2da15fef7831c878d082deb34e2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 14 Aug 2013 11:15:25 -0400 Subject: [PATCH] common: return -1 download percent if download hasn't started [GH-288] --- CHANGELOG.md | 7 +++++++ builder/virtualbox/step_download_iso.go | 5 ++++- builder/vmware/step_download_iso.go | 5 ++++- common/download.go | 6 +++--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f6f41c9b..4e87b06a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,13 @@ IMPROVEMENTS: only check at execution. * command/build: A path of "-" will read the template from stdin. +BUG FIXES: + +* builder/virtualbox: dowload progress won't be shown until download + actually starts. [GH-288] +* builder/vmware: dowload progress won't be shown until download + actually starts. [GH-288] + ## 0.3.1 (August 12, 2013) IMPROVEMENTS: diff --git a/builder/virtualbox/step_download_iso.go b/builder/virtualbox/step_download_iso.go index 045a3da7c..39bcea3de 100644 --- a/builder/virtualbox/step_download_iso.go +++ b/builder/virtualbox/step_download_iso.go @@ -69,7 +69,10 @@ DownloadWaitLoop: break DownloadWaitLoop case <-progressTicker.C: - ui.Message(fmt.Sprintf("Download progress: %d%%", download.PercentProgress())) + progress := download.PercentProgress() + if progress >= 0 { + ui.Message(fmt.Sprintf("Download progress: %d%%", progress)) + } case <-time.After(1 * time.Second): if _, ok := state[multistep.StateCancelled]; ok { ui.Say("Interrupt received. Cancelling download...") diff --git a/builder/vmware/step_download_iso.go b/builder/vmware/step_download_iso.go index 9c27ca879..999138f49 100644 --- a/builder/vmware/step_download_iso.go +++ b/builder/vmware/step_download_iso.go @@ -71,7 +71,10 @@ DownloadWaitLoop: break DownloadWaitLoop case <-progressTicker.C: - ui.Say(fmt.Sprintf("Download progress: %d%%", download.PercentProgress())) + progress := download.PercentProgress() + if progress >= 0 { + ui.Message(fmt.Sprintf("Download progress: %d%%", progress)) + } case <-time.After(1 * time.Second): if _, ok := state[multistep.StateCancelled]; ok { ui.Say("Interrupt received. Cancelling download...") diff --git a/common/download.go b/common/download.go index 6edf43620..a70a1485c 100644 --- a/common/download.go +++ b/common/download.go @@ -148,12 +148,12 @@ func (d *DownloadClient) Get() (string, error) { } // PercentProgress returns the download progress as a percentage. -func (d *DownloadClient) PercentProgress() uint { +func (d *DownloadClient) PercentProgress() int { if d.downloader == nil { - return 0 + return -1 } - return uint((float64(d.downloader.Progress()) / float64(d.downloader.Total())) * 100) + return int((float64(d.downloader.Progress()) / float64(d.downloader.Total())) * 100) } // VerifyChecksum tests that the path matches the checksum for the