main
Raw Download raw file
 1//go:build !plan9 && !windows && !wasm
 2// +build !plan9,!windows,!wasm
 3
 4package osfs
 5
 6import (
 7	"os"
 8	"syscall"
 9
10	"golang.org/x/sys/unix"
11)
12
13func (f *file) Lock() error {
14	f.m.Lock()
15	defer f.m.Unlock()
16
17	return unix.Flock(int(f.File.Fd()), unix.LOCK_EX)
18}
19
20func (f *file) Unlock() error {
21	f.m.Lock()
22	defer f.m.Unlock()
23
24	return unix.Flock(int(f.File.Fd()), unix.LOCK_UN)
25}
26
27func rename(from, to string) error {
28	return os.Rename(from, to)
29}
30
31// umask sets umask to a new value, and returns a func which allows the
32// caller to reset it back to what it was originally.
33func umask(new int) func() {
34	old := syscall.Umask(new)
35	return func() {
36		syscall.Umask(old)
37	}
38}