Code to more securely create anonymous temp files on Linux

This commit is contained in:
Kovid Goyal
2023-01-26 11:34:46 +05:30
parent 3a126ffa9d
commit 4185e30d73
2 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
//go:build !linux
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
package utils
import (
"fmt"
"os"
)
var _ = fmt.Print
func CreateAnonymousTemp(dir string) (*os.File, error) {
f, err := os.CreateTemp(dir, "")
if err != nil {
return nil, err
}
err = os.Remove(f.Name())
if err != nil {
f.Close()
return nil, err
}
return f, err
}