From cbac2896d7da4464baded30b298c9d94d995d1d6 Mon Sep 17 00:00:00 2001 From: pamiel <14542297+pamiel@users.noreply.github.com> Date: Thu, 4 Apr 2019 10:12:40 +0200 Subject: [PATCH] Using Go's tmpDir instead of shell's mkdir --- pkg/helm/helm.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index f30c433..29364b0 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -17,6 +17,7 @@ import ( "strings" "strconv" "bufio" + "io/ioutil" "fmt" "os" "os/exec" @@ -304,12 +305,19 @@ func Status(chart string) HelmStatus { // Fetch ... func Fetch(chart string, version string) string { + tempDir, err := ioutil.TempDir("", "spray-") + if err != nil { + printError(err) + } + defer os.RemoveAll(tempDir) + var command string if version != "" { - command = "mkdir /tmp/$$ && helm fetch " + chart + " --destination /tmp/$$ --version " + version + " && ls /tmp/$$ && mv /tmp/$$/* . && rmdir /tmp/$$" + command = "helm fetch " + chart + " --destination " + tempDir + " --version " + version } else { - command = "mkdir /tmp/$$ && helm fetch " + chart + " --destination /tmp/$$ && ls /tmp/$$ && mv /tmp/$$/* . && rmdir /tmp/$$" + command = "helm fetch " + chart + " --destination " + tempDir } + command = command + " && ls " + tempDir + " && cp " + tempDir + "/* ." cmd := exec.Command("sh", "-c", command) cmdOutput := &bytes.Buffer{}