@@ -43,11 +43,9 @@ func getClient() *http.Client {
4343 Dial : defaultTimeout ,
4444 }
4545
46- client := http.Client {
46+ return & http.Client {
4747 Transport : & transport ,
4848 }
49-
50- return & client
5149}
5250
5351func getRequest (apiURL string ) (* http.Request , error ) {
@@ -204,11 +202,7 @@ func (*b2dReleaseGetter) download(dir, file, isoURL string) error {
204202 return err
205203 }
206204
207- if err := os .Rename (f .Name (), dest ); err != nil {
208- return err
209- }
210-
211- return nil
205+ return os .Rename (f .Name (), dest )
212206}
213207
214208// iso is an ISO volume.
@@ -305,6 +299,7 @@ func NewB2dUtils(storePath string) *B2dUtils {
305299
306300// DownloadISO downloads boot2docker ISO image for the given tag and save it at dest.
307301func (b * B2dUtils ) DownloadISO (dir , file , isoURL string ) error {
302+ log .Infof ("Downloading %s from %s..." , b .path (), isoURL )
308303 return b .download (dir , file , isoURL )
309304}
310305
@@ -351,72 +346,60 @@ func (b *B2dUtils) DownloadLatestBoot2Docker(apiURL string) error {
351346}
352347
353348func (b * B2dUtils ) DownloadISOFromURL (latestReleaseURL string ) error {
354- log .Infof ("Downloading %s to %s..." , latestReleaseURL , b .path ())
355- if err := b .DownloadISO (b .imgCachePath , b .filename (), latestReleaseURL ); err != nil {
356- return err
357- }
358-
359- return nil
349+ return b .DownloadISO (b .imgCachePath , b .filename (), latestReleaseURL )
360350}
361351
362- func (b * B2dUtils ) CopyIsoToMachineDir (isoURL , machineName string ) error {
363- // TODO: This is a bit off-color.
364- machineDir := filepath .Join (b .storePath , "machines" , machineName )
365- machineIsoPath := filepath .Join (machineDir , b .filename ())
366-
367- // just in case the cache dir has been manually deleted,
368- // check for it and recreate it if it's gone
352+ func (b * B2dUtils ) UpdateISOCache (isoURL string ) error {
353+ // recreate the cache dir if it has been manually deleted
369354 if _ , err := os .Stat (b .imgCachePath ); os .IsNotExist (err ) {
370- log .Infof ("Image cache does not exist, creating it at %s..." , b .imgCachePath )
355+ log .Infof ("Image cache directory does not exist, creating it at %s..." , b .imgCachePath )
371356 if err := os .Mkdir (b .imgCachePath , 0700 ); err != nil {
372357 return err
373358 }
374359 }
375360
376- // By default just copy the existing "cached" iso to the machine's directory...
377- if isoURL == "" {
378- return b . copyDefaultISOToMachine ( machineIsoPath )
361+ if isoURL != "" {
362+ // Non-default B2D are not cached
363+ return nil
379364 }
380365
381- // if ISO is specified, check if it matches a github releases url or fallback to a direct download
382- downloadURL , err := b . getReleaseURL ( isoURL )
383- if err != nil {
384- return err
366+ exists := b . exists ()
367+ if ! exists {
368+ log . Info ( "No default Boot2Docker ISO found locally, downloading the latest release..." )
369+ return b . DownloadLatestBoot2Docker ( "" )
385370 }
386371
387- log .Infof ("Downloading %s from %s..." , b .filename (), downloadURL )
388- return b .DownloadISO (machineDir , b .filename (), downloadURL )
372+ latest := b .isLatest ()
373+ if ! latest {
374+ log .Info ("Default Boot2Docker ISO is out-of-date, downloading the latest release..." )
375+ return b .DownloadLatestBoot2Docker ("" )
376+ }
377+
378+ return nil
389379}
390380
391- func (b * B2dUtils ) copyDefaultISOToMachine (machineIsoPath string ) error {
392- // just in case the cache dir has been manually deleted,
393- // check for it and recreate it if it's gone
394- if _ , err := os .Stat (b .imgCachePath ); os .IsNotExist (err ) {
395- log .Infof ("Image cache directory does not exist, creating it at %s..." , b .imgCachePath )
396- if err := os .Mkdir (b .imgCachePath , 0700 ); err != nil {
397- return err
398- }
381+ func (b * B2dUtils ) CopyIsoToMachineDir (isoURL , machineName string ) error {
382+ if err := b .UpdateISOCache (isoURL ); err != nil {
383+ return err
399384 }
400385
401- exists := b .exists ()
402- latest := b .isLatest ()
386+ // TODO: This is a bit off-color.
387+ machineDir := filepath .Join (b .storePath , "machines" , machineName )
388+ machineIsoPath := filepath .Join (machineDir , b .filename ())
403389
404- if exists && latest {
405- log .Infof ("Latest Boot2Docker ISO found locally, copying it to %s..." , machineIsoPath )
390+ // By default just copy the existing "cached" iso to the machine's directory...
391+ if isoURL == "" {
392+ log .Infof ("Copying %s to %s..." , b .path (), machineIsoPath )
406393 return CopyFile (b .path (), machineIsoPath )
407394 }
408395
409- if ! exists {
410- log .Info ("No default Boot2Docker ISO found locally, downloading the latest release..." )
411- } else if ! latest {
412- log .Info ("Default Boot2Docker ISO is out-of-date, downloading the latest release..." )
413- }
414- if err := b .DownloadLatestBoot2Docker ("" ); err != nil {
396+ // if ISO is specified, check if it matches a github releases url or fallback to a direct download
397+ downloadURL , err := b .getReleaseURL (isoURL )
398+ if err != nil {
415399 return err
416400 }
417401
418- log .Infof ("Copying %s to %s..." , b .path (), machineIsoPath )
419- return CopyFile (b .path (), machineIsoPath )
402+ return b .DownloadISO (machineDir , b .filename (), downloadURL )
420403}
421404
422405// isLatest checks the latest release tag and
0 commit comments