From 3d98504c4c2d3d0426855a708baa0b975d6bf406 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Fri, 22 Sep 2017 13:20:13 -0400 Subject: [PATCH] common: WriteFileAtomic use tempfile in current dir --- common/os.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/os.go b/common/os.go index 9c2bda508..71ee88422 100644 --- a/common/os.go +++ b/common/os.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "os/signal" + "path/filepath" "strings" ) @@ -101,7 +102,8 @@ func MustWriteFile(filePath string, contents []byte, mode os.FileMode) { // WriteFileAtomic writes newBytes to temp and atomically moves to filePath // when everything else succeeds. func WriteFileAtomic(filePath string, newBytes []byte, mode os.FileMode) error { - f, err := ioutil.TempFile("", "") + dir := filepath.Dir(filePath) + f, err := ioutil.TempFile(dir, "") if err != nil { return err }