Skip to content

Commit 5643143

Browse files
author
lgmugnier
authored
Merge pull request #1 from bastionzero/fnctllock
Use fnctl lock instead of flock on unix
2 parents 126854a + a3969d4 commit 5643143

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

leveldb/storage/file_storage_unix.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@ func newFileLock(path string, readOnly bool) (fl fileLock, err error) {
4949
}
5050

5151
func setFileLock(f *os.File, readOnly, lock bool) error {
52-
how := syscall.LOCK_UN
52+
flock := syscall.Flock_t{
53+
Type: syscall.F_UNLCK,
54+
Start: 0,
55+
Len: 0,
56+
Whence: 1,
57+
}
5358
if lock {
5459
if readOnly {
55-
how = syscall.LOCK_SH
60+
flock.Type = syscall.F_RDLCK
5661
} else {
57-
how = syscall.LOCK_EX
62+
flock.Type = syscall.F_WRLCK
5863
}
5964
}
60-
return syscall.Flock(int(f.Fd()), how|syscall.LOCK_NB)
65+
return syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &flock)
6166
}
6267

6368
func rename(oldpath, newpath string) error {

0 commit comments

Comments
 (0)