From 3194ec7026656fd0f19146d21ea02c70d2166505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Mon, 25 Mar 2019 20:30:39 +0100 Subject: [PATCH] Use a temp file, when writing the cached image --- pkg/minikube/machine/cache_images.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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 }