| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package osfs |
| 5 |
|
| 6 |
import ( |
| 7 |
"os" |
| 8 |
"syscall" |
| 9 |
|
| 10 |
"golang.org/x/sys/unix" |
| 11 |
) |
| 12 |
|
| 13 |
func (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 |
|
| 20 |
func (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 |
|
| 27 |
func rename(from, to string) error { |
| 28 |
return os.Rename(from, to) |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
func umask(new int) func() { |
| 34 |
old := syscall.Umask(new) |
| 35 |
return func() { |
| 36 |
syscall.Umask(old) |
| 37 |
} |
| 38 |
} |