From 7fd2e4d2dbd5f844c59060c11ce562a6fcdaabeb Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 22 Sep 2014 15:39:25 +0200 Subject: [PATCH] Use temp file in same location as final .stignore --- model/model.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/model/model.go b/model/model.go index a03395126..dc6dc7911 100644 --- a/model/model.go +++ b/model/model.go @@ -10,7 +10,7 @@ import ( "errors" "fmt" "io" - "io/ioutil" + "math/rand" "net" "os" "path/filepath" @@ -617,11 +617,13 @@ func (m *Model) SetIgnores(repo string, content []string) error { return fmt.Errorf("Repo %s does not exist", repo) } - fd, err := ioutil.TempFile("", "stignore-"+repo) + tmpFileName := filepath.Join(cfg.Directory, fmt.Sprintf(".stignore.%d", rand.Int63())) + fd, err := os.Create(tmpFileName) if err != nil { l.Warnln("Saving .stignore:", err) return err } + defer os.Remove(tmpFileName) writer := bufio.NewWriter(fd) for _, line := range content {