Use ioutil.TempFile, not some nasty homebrew crap

This commit is contained in:
Jakob Borg 2014-09-22 15:54:36 +02:00
parent 4ddd87e773
commit 9797f62cb8
1 changed files with 4 additions and 5 deletions

View File

@ -10,7 +10,7 @@ import (
"errors"
"fmt"
"io"
"math/rand"
"io/ioutil"
"net"
"os"
"path/filepath"
@ -617,13 +617,12 @@ func (m *Model) SetIgnores(repo string, content []string) error {
return fmt.Errorf("Repo %s does not exist", repo)
}
tmpFileName := filepath.Join(cfg.Directory, fmt.Sprintf(".stignore.%d", rand.Int63()))
fd, err := os.Create(tmpFileName)
fd, err := ioutil.TempFile(cfg.Directory, "stignore-"+repo)
if err != nil {
l.Warnln("Saving .stignore:", err)
return err
}
defer os.Remove(tmpFileName)
defer os.Remove(fd.Name())
writer := bufio.NewWriter(fd)
for _, line := range content {
@ -637,7 +636,7 @@ func (m *Model) SetIgnores(repo string, content []string) error {
}
file := filepath.Join(cfg.Directory, ".stignore")
err = osutil.Rename(tmpFileName, file)
err = osutil.Rename(fd.Name(), file)
if err != nil {
l.Warnln("Saving .stignore:", err)
return err