From a2253558ef5c70479b8b69f897c0b64e143fe792 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Mon, 11 Nov 2024 16:55:37 +0000 Subject: [PATCH] Use lock file. --- vfs/README.md | 1 - vfs/os_dotlk.go | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vfs/README.md b/vfs/README.md index cf0e3c30..08777972 100644 --- a/vfs/README.md +++ b/vfs/README.md @@ -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) diff --git a/vfs/os_dotlk.go b/vfs/os_dotlk.go index 1c1a49c1..b00a1865 100644 --- a/vfs/os_dotlk.go +++ b/vfs/os_dotlk.go @@ -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. }