fix regression for custom b2d url paths

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett 2015-03-18 13:16:19 -04:00
parent bc9e5c6a04
commit 2151492dec
2 changed files with 30 additions and 15 deletions

View File

@ -177,17 +177,14 @@ func (d *Driver) Create() error {
if err := os.Mkdir(imgPath, 0700); err != nil { if err := os.Mkdir(imgPath, 0700); err != nil {
return err return err
} }
} }
if d.Boot2DockerURL != "" { if d.Boot2DockerURL != "" {
isoURL = d.Boot2DockerURL isoURL = d.Boot2DockerURL
log.Infof("Downloading %s from %s...", isoFilename, isoURL) log.Infof("Downloading %s from %s...", isoFilename, isoURL)
if err := b2dutils.DownloadISO(commonIsoPath, isoFilename, isoURL); err != nil { if err := b2dutils.DownloadISO(imgPath, isoFilename, isoURL); err != nil {
return err return err
} }
} else { } else {
// todo: check latest release URL, download if it's new // todo: check latest release URL, download if it's new
// until then always use "latest" // until then always use "latest"
@ -202,12 +199,12 @@ func (d *Driver) Create() error {
return err return err
} }
} }
}
isoDest := filepath.Join(d.storePath, isoFilename) isoDest := filepath.Join(d.storePath, isoFilename)
if err := utils.CopyFile(commonIsoPath, isoDest); err != nil { if err := utils.CopyFile(commonIsoPath, isoDest); err != nil {
return err return err
} }
}
log.Infof("Creating SSH key...") log.Infof("Creating SSH key...")

View File

@ -7,6 +7,7 @@ import (
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
"net/url"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
@ -84,29 +85,46 @@ func (b *B2dUtils) GetLatestBoot2DockerReleaseURL() (string, error) {
} }
// Download boot2docker ISO image for the given tag and save it at dest. // Download boot2docker ISO image for the given tag and save it at dest.
func (b *B2dUtils) DownloadISO(dir, file, url string) error { func (b *B2dUtils) DownloadISO(dir, file, isoUrl string) error {
client := getClient() u, err := url.Parse(isoUrl)
rsp, err := client.Get(url) var src io.ReadCloser
if u.Scheme == "file" {
s, err := os.Open(u.Path)
if err != nil { if err != nil {
return err return err
} }
defer rsp.Body.Close() src = s
} else {
client := getClient()
s, err := client.Get(isoUrl)
if err != nil {
return err
}
src = s.Body
}
defer src.Close()
// Download to a temp file first then rename it to avoid partial download. // Download to a temp file first then rename it to avoid partial download.
f, err := ioutil.TempFile(dir, file+".tmp") f, err := ioutil.TempFile(dir, file+".tmp")
if err != nil { if err != nil {
return err return err
} }
defer os.Remove(f.Name()) defer os.Remove(f.Name())
if _, err := io.Copy(f, rsp.Body); err != nil {
if _, err := io.Copy(f, src); err != nil {
// TODO: display download progress? // TODO: display download progress?
return err return err
} }
if err := f.Close(); err != nil { if err := f.Close(); err != nil {
return err return err
} }
if err := os.Rename(f.Name(), filepath.Join(dir, file)); err != nil { if err := os.Rename(f.Name(), filepath.Join(dir, file)); err != nil {
return err return err
} }
return nil return nil
} }