Fix macOS compatibility: wiki-lock.sh flock fallback + test whitespace - #145
Open
emircbngl wants to merge 1 commit into
Open
Fix macOS compatibility: wiki-lock.sh flock fallback + test whitespace#145emircbngl wants to merge 1 commit into
emircbngl wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On macOS/BSD there is no
flock, sowith_meta_lockinscripts/wiki-lock.shfails on the very firstacquirewithflock: 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 BSDwcpads its counts with leading spaces andassert_eqcompared them as strings (expected '10', got ' 10').Repro on macOS:
Changes
scripts/wiki-lock.sh—with_meta_locknow detectsflock. On Linux/util-linux the originalflockpath is unchanged. Whenflockis absent it falls back to an atomicmkdirlock (atomic on every POSIX filesystem), with a ~5s bounded retry matchingflock -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 underset -e.tests/test_wiki_lock.sh,tests/test_concurrent_write.sh—assert_eqtrims leading/trailing whitespace before comparing, so BSDwc'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)mkdirfallback: 10 concurrent writers, no leaked lockfiles, no torn/garbled lines.flockbranch is byte-identical to before).🤖 Generated with Claude Code