]> Cypherpunks.ru repositories - gocheese.git/commitdiff
Use native os.CreateTemp instead of own one
authorSergey Matveev <stargrave@stargrave.org>
Thu, 3 Nov 2022 14:16:24 +0000 (17:16 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 3 Nov 2022 14:17:13 +0000 (17:17 +0300)
fileutils.go
main.go

index 34e6e748956922fb8d7a79ac234828514d3da960..aec22c64573304de084db76bf63294facf2928e4 100644 (file)
@@ -22,17 +22,25 @@ import (
        "net/http"
        "os"
        "path/filepath"
-       "strconv"
        "time"
 )
 
-var NoSync = os.Getenv("GOCHEESE_NO_SYNC") == "1"
+var (
+       NoSync   = os.Getenv("GOCHEESE_NO_SYNC") == "1"
+       UmaskCur int
+)
 
 func TempFile(dir string) (*os.File, error) {
-       // Assume that probability of suffix collision is negligible
-       suffix := strconv.FormatInt(time.Now().UnixNano()+int64(os.Getpid()), 16)
-       name := filepath.Join(dir, "nncp"+suffix)
-       return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, os.FileMode(0666))
+       tmp, err := os.CreateTemp(dir, "gocheese")
+       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
 }
 
 func DirSync(dirPath string) error {
diff --git a/main.go b/main.go
index 08c75535c1491feb8ac230f754cb37b63086e4c2..da276a6ceaae5e50ace659a3ef664b8f0b22bcab 100644 (file)
--- a/main.go
+++ b/main.go
@@ -44,7 +44,7 @@ import (
 )
 
 const (
-       Version   = "3.5.0"
+       Version   = "3.6.0"
        UserAgent = "GoCheese/" + Version
 )
 
@@ -212,6 +212,9 @@ func main() {
                log.Fatalln("Both -tls-cert and -tls-key are required")
        }
 
+       UmaskCur = syscall.Umask(0)
+       syscall.Umask(UmaskCur)
+
        var err error
        PyPIURLParsed, err = url.Parse(*PyPIURL)
        if err != nil {