Skip to content

Fix macOS compatibility: wiki-lock.sh flock fallback + test whitespace - #145

Open
emircbngl wants to merge 1 commit into
AgriciDaniel:mainfrom
emircbngl:fix/macos-compat-flock-and-wc
Open

Fix macOS compatibility: wiki-lock.sh flock fallback + test whitespace#145
emircbngl wants to merge 1 commit into
AgriciDaniel:mainfrom
emircbngl:fix/macos-compat-flock-and-wc

Conversation

@emircbngl

Copy link
Copy Markdown

Problem

On macOS/BSD there is no flock, so with_meta_lock in scripts/wiki-lock.sh fails on the very first acquire with flock: command not found, breaking every wiki-lock operation (acquire/release/list/peek). The bundled tests also fail on macOS even when the values are correct, because BSD wc pads its counts with leading spaces and assert_eq compared them as strings (expected '10', got ' 10').

Repro on macOS:

WIKI_LOCK_VAULT=<vault> bash scripts/wiki-lock.sh acquire wiki/hot.md
# -> scripts/wiki-lock.sh: line 156: flock: command not found

Changes

  • scripts/wiki-lock.shwith_meta_lock now detects flock. On Linux/util-linux the original flock path is unchanged. When flock is absent it falls back to an atomic mkdir lock (atomic on every POSIX filesystem), with a ~5s bounded retry matching flock -w 5, an age-based reap so a crashed holder can't wedge the lock, and cleanup on both normal return and an unexpected exit. A valid non-zero return (75 = lock held) is preserved under set -e.
  • tests/test_wiki_lock.sh, tests/test_concurrent_write.shassert_eq trims leading/trailing whitespace before comparing, so BSD wc's padding no longer fails a correct numeric assertion.

Verification (macOS)

  • tests/test_wiki_lock.sh: 16/16 pass (was 15/1)
  • tests/test_concurrent_write.sh: 6/6 pass (was 3/3)
  • Concurrency invariants hold under the mkdir fallback: 10 concurrent writers, no leaked lockfiles, no torn/garbled lines.
  • Linux behavior is unchanged (the flock branch is byte-identical to before).

🤖 Generated with Claude Code

macOS/BSD ship no `flock`, so `with_meta_lock` failed on the first
acquire with "flock: command not found", breaking every wiki-lock
operation (acquire/release/list/peek) on Mac.

- wiki-lock.sh: detect `flock`; when present, keep the existing
  Linux path unchanged. When absent, fall back to an atomic `mkdir`
  lock (atomic on every POSIX fs) with a ~5s bounded retry matching
  `flock -w 5`, an age-based reap so a crashed holder cannot wedge
  the lock, and cleanup on both normal return and an unexpected exit.
  A valid non-zero return (75 = lock held) is preserved under `set -e`.
- tests: `assert_eq` trimmed leading/trailing whitespace before
  comparing, because BSD/macOS `wc` pads counts with spaces and made
  correct numeric assertions fail (expected '10', got '      10').

Verified on macOS: test_wiki_lock.sh 16/16 and
test_concurrent_write.sh 6/6 pass (were 15/1 and 3/3 before), and the
concurrency invariants hold (no leaked locks, no torn writes).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@emircbngl
emircbngl requested a review from AgriciDaniel as a code owner July 29, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant