aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/lockedfile/lockedfile_filelock.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-10-13 20:57:16 +0900
committerOphestra <cat@gensokyo.uk>2026-10-13 20:57:16 +0900
commit9e95987536f895ef1a989fcd9e69ab84a1b94a17 (patch)
tree304aec06573103329df9caf3adea58d1b7025700 /internal/lockedfile/lockedfile_filelock.go
parent0abf367b1334b76f5e8f989cf0c07b5d00b25868 (diff)
internal/lockedfile: optionally force write lock
For acquiring a write lock on a directory. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/lockedfile/lockedfile_filelock.go')
-rw-r--r--internal/lockedfile/lockedfile_filelock.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/internal/lockedfile/lockedfile_filelock.go b/internal/lockedfile/lockedfile_filelock.go
index 9fc16a9b..1f5ca310 100644
--- a/internal/lockedfile/lockedfile_filelock.go
+++ b/internal/lockedfile/lockedfile_filelock.go
@@ -13,7 +13,7 @@ import (
"hakurei.app/internal/lockedfile/internal/filelock"
)
-func openFile(name string, flag int, perm fs.FileMode) (*os.File, error) {
+func osOpenFile(name string, flag int, perm fs.FileMode, w bool) (*os.File, error) {
// On BSD systems, we could add the O_SHLOCK or O_EXLOCK flag to the OpenFile
// call instead of locking separately, but we have to support separate locking
// calls for Linux and Windows anyway, so it's simpler to use that approach
@@ -24,6 +24,10 @@ func openFile(name string, flag int, perm fs.FileMode) (*os.File, error) {
return nil, err
}
+ if w {
+ flag |= os.O_WRONLY
+ }
+
switch flag & (os.O_RDONLY | os.O_WRONLY | os.O_RDWR) {
case os.O_WRONLY, os.O_RDWR:
err = filelock.Lock(f)