From 08d97cf0258e92d82850fcc56f608008cc39d04f Mon Sep 17 00:00:00 2001 From: tstromberg Date: Tue, 6 Aug 2019 16:01:06 -0700 Subject: [PATCH] Use a temp dest to atomically download the iso --- pkg/util/downloader.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/util/downloader.go b/pkg/util/downloader.go index 6a6059110edb..81d951276a2d 100644 --- a/pkg/util/downloader.go +++ b/pkg/util/downloader.go @@ -65,10 +65,14 @@ func (f DefaultDownloader) CacheMinikubeISOFromURL(url string) error { urlWithChecksum = url + "?checksum=file:" + constants.DefaultISOSHAURL } + dst := f.GetISOCacheFilepath(url) + // Predictable temp destination so that resume can function + tmpDst := dst + ".download" + opts := []getter.ClientOption{getter.WithProgress(defaultProgressBar)} client := &getter.Client{ Src: urlWithChecksum, - Dst: f.GetISOCacheFilepath(url), + Dst: tmpDst, Mode: getter.ClientModeFile, Options: opts, } @@ -78,7 +82,7 @@ func (f DefaultDownloader) CacheMinikubeISOFromURL(url string) error { if err := client.Get(); err != nil { return errors.Wrap(err, url) } - return nil + return os.Rename(tmpDst, dst) } // ShouldCacheMinikubeISO returns if we need to download the ISO