From 71ff56f9d3dfe31601ffba2404c535c17545b15f Mon Sep 17 00:00:00 2001 From: Lonnie Liu Date: Mon, 15 Feb 2021 09:19:49 -0800 Subject: [PATCH] fix temp file pattern new golang std lib forbids path separator in file pattern for security reasons. --- file/util.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/file/util.go b/file/util.go index a9f81d2..0ddbb20 100644 --- a/file/util.go +++ b/file/util.go @@ -1,11 +1,13 @@ package file import ( - "github.com/sirupsen/logrus" "io/ioutil" "math/rand" + "path/filepath" "strings" "time" + + "github.com/sirupsen/logrus" ) const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -37,7 +39,8 @@ func toMap(str string) map[string]string { } func (d *Dapperfile) tempfile(content []byte) (string, error) { - tempfile, err := ioutil.TempFile(".", d.File) + dir, base := filepath.Dir(d.File), filepath.Base(d.File) + tempfile, err := ioutil.TempFile(dir, base) if err != nil { return "", err }