diff --git a/pkg/minikube/machine/cache_images.go b/pkg/minikube/machine/cache_images.go index 7866bfbf7d0e..3a0761e080a4 100644 --- a/pkg/minikube/machine/cache_images.go +++ b/pkg/minikube/machine/cache_images.go @@ -314,10 +314,21 @@ func CacheImage(image, dst string) error { } glog.Infoln("OPENING: ", dstPath) - f, err := os.Create(dstPath) + f, err := ioutil.TempFile(filepath.Dir(dstPath), filepath.Base(dstPath)+".*.tmp") if err != nil { return err } - defer f.Close() - return tarball.Write(tag, img, nil, f) + err = tarball.Write(tag, img, nil, f) + if err != nil { + return err + } + err = f.Close() + if err != nil { + return err + } + err = os.Rename(f.Name(), dstPath) + if err != nil { + return err + } + return nil }