From f2dd8d8a515c1a2a220836231ad1a671a5e9b73d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 13 Apr 2026 08:09:33 +0300 Subject: ask: serialize concurrent CLI with repo lock and stale PID recovery Add advisory lock under .git/hexai-ask.lock around Taskwarrior execution, with metadata (PID and process basename) and Linux /proc comm checks to remove orphan lock files when the recorded holder is gone or not ask. Extract internal/filelock for shared flock helpers; stats uses it too. Made-with: Cursor --- internal/filelock/lock_windows.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 internal/filelock/lock_windows.go (limited to 'internal/filelock/lock_windows.go') diff --git a/internal/filelock/lock_windows.go b/internal/filelock/lock_windows.go new file mode 100644 index 0000000..058b942 --- /dev/null +++ b/internal/filelock/lock_windows.go @@ -0,0 +1,24 @@ +//go:build windows + +package filelock + +import ( + "golang.org/x/sys/windows" +) + +func tryLockExclusive(fd uintptr) error { + var ol windows.Overlapped + err := windows.LockFileEx(windows.Handle(fd), windows.LOCKFILE_EXCLUSIVE_LOCK|windows.LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, &ol) + if err == nil { + return nil + } + if err == windows.ERROR_LOCK_VIOLATION { + return ErrWouldBlock + } + return err +} + +func unlockExclusive(fd uintptr) error { + var ol windows.Overlapped + return windows.UnlockFileEx(windows.Handle(fd), 0, 1, 0, &ol) +} -- cgit v1.2.3