X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=tmp.go;h=f64a44f3dc7cd1706e2e65fb8dda2c83875f567e;hb=ae56a3b66db9f60612f656b0046427ef139c2119;hp=1d8a3f29d3d97d923da14eed030610014fb0d28f;hpb=0030b3e73152bf9d9ad3e435fa42e607c7865321;p=goredo.git diff --git a/tmp.go b/tmp.go index 1d8a3f2..f64a44f 100644 --- a/tmp.go +++ b/tmp.go @@ -21,17 +21,17 @@ package main import ( "os" - "path" - "strconv" - "time" ) -func tempsuffix() string { - return strconv.FormatInt((time.Now().UnixNano()+int64(os.Getpid()))&0xFFFFFFFF, 16) -} - func tempfile(dir, prefix string) (*os.File, error) { - // It respects umask, unlike ioutil.TempFile - name := path.Join(dir, TmpPrefix+prefix+"."+tempsuffix()) - return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, os.FileMode(0666)) + tmp, err := os.CreateTemp(dir, TmpPrefix+prefix+".") + if err != nil { + return nil, err + } + err = os.Chmod(tmp.Name(), os.FileMode(0666&^UmaskCur)) + if err != nil { + tmp.Close() + return nil, err + } + return tmp, nil }