Skip to content

Commit

Permalink
Use lock file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Nov 11, 2024
1 parent 466d14a commit a225355
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
1 change: 0 additions & 1 deletion vfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ like SQLite.

You can also opt into a cross-platform locking implementation
with the `sqlite3_dotlk` build tag.
The only requirement is an atomic `os.Mkdir`.

Otherwise, file locking is not supported, and you must use
[`nolock=1`](https://sqlite.org/uri.html#urinolock)
Expand Down
3 changes: 2 additions & 1 deletion vfs/os_dotlk.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func osGetSharedLock(file *os.File) _ErrorCode {
name := file.Name()
locker := vfsDotLocks[name]
if locker == nil {
err := os.Mkdir(name+".lock", 0777)
f, err := os.OpenFile(name+".lock", os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
f.Close()
if errors.Is(err, fs.ErrExist) {
return _BUSY // Another process has the lock.
}
Expand Down

0 comments on commit a225355

Please sign in to comment.