From b41a3cd4239d4fe060d08d0789982a6a71e0429f Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 23 Dec 2020 17:27:56 -0700 Subject: [PATCH] WIP: create tmp files in HOME when using snap --- pkg/minikube/command/kic_runner.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/minikube/command/kic_runner.go b/pkg/minikube/command/kic_runner.go index ae14308a22cb..5019ae5e1a82 100644 --- a/pkg/minikube/command/kic_runner.go +++ b/pkg/minikube/command/kic_runner.go @@ -24,6 +24,7 @@ import ( "os" "os/exec" "path" + "path/filepath" "runtime" "strconv" "strings" @@ -185,7 +186,11 @@ func (k *kicRunner) Copy(f assets.CopyableFile) error { } } klog.Infof("%s (temp): %s --> %s (%d bytes)", k.ociBin, src, dst, f.GetLength()) - tf, err := ioutil.TempFile("", "tmpf-memory-asset") + tmpFolder := "" + if isSnapBinary() { + tmpFolder = os.Getenv("HOME") + } + tf, err := ioutil.TempFile(tmpFolder, "tmpf-memory-asset") if err != nil { return errors.Wrap(err, "creating temporary file") } @@ -197,6 +202,15 @@ func (k *kicRunner) Copy(f assets.CopyableFile) error { return k.copy(tf.Name(), dst) } +func isSnapBinary() bool { + ex, err := os.Executable() + if err != nil { + return false + } + exPath := filepath.Dir(ex) + return strings.Contains(exPath, "snap") +} + func (k *kicRunner) copy(src string, dst string) error { fullDest := fmt.Sprintf("%s:%s", k.nameOrID, dst) if k.ociBin == oci.Podman {