mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 18:41:59 -07:00
Use ioutil.TempFile, not some nasty homebrew crap
This commit is contained in:
parent
4ddd87e773
commit
9797f62cb8
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user