mirror of https://github.com/siddontang/go.git
avoid cross device
avoid dir nil. if dir is nil, writeAtomic creatae tempfile in system temporary dir and cross device
This commit is contained in:
parent
6463c39726
commit
9f05833051
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
// Write file to temp and atomically move when everything else succeeds.
|
// Write file to temp and atomically move when everything else succeeds.
|
||||||
func WriteFileAtomic(filename string, data []byte, perm os.FileMode) error {
|
func WriteFileAtomic(filename string, data []byte, perm os.FileMode) error {
|
||||||
dir, name := path.Split(filename)
|
dir, name := path.Dir(filename), path.Base(filename)
|
||||||
f, err := ioutil.TempFile(dir, name)
|
f, err := ioutil.TempFile(dir, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue