18 lines
373 B
Go
18 lines
373 B
Go
|
|
//go:build !windows
|
||
|
|
|
||
|
|
package securefile
|
||
|
|
|
||
|
|
import (
|
||
|
|
"golang.org/x/sys/unix"
|
||
|
|
"os"
|
||
|
|
)
|
||
|
|
|
||
|
|
func protect(path string, directory bool) error {
|
||
|
|
if directory {
|
||
|
|
return os.Chmod(path, 0700)
|
||
|
|
}
|
||
|
|
return os.Chmod(path, 0600)
|
||
|
|
}
|
||
|
|
func lockFile(f *os.File) error { return unix.Flock(int(f.Fd()), unix.LOCK_EX) }
|
||
|
|
func unlockFile(f *os.File) { _ = unix.Flock(int(f.Fd()), unix.LOCK_UN) }
|