Skip to content

docs: document cache fix (unlock-before-rename), atomic writes, file locking, and test hardening#78

Merged
umpire274 merged 4 commits intomainfrom
v0.5.5
Nov 10, 2025
Merged

docs: document cache fix (unlock-before-rename), atomic writes, file locking, and test hardening#78
umpire274 merged 4 commits intomainfrom
v0.5.5

Conversation

@umpire274
Copy link
Owner

  • Document the fix that releases the cache file lock before replacing the JSON store (avoids Windows "file in use" errors).
  • Note atomic writes to the shared JSON cache (write to temp file + rename) and a Windows fallback (remove + rename).
  • Describe advisory file locking via fs2 and the open_and_lock() helper centralizing locking logic.
  • Mention the switch to anyhow::Result for richer internal error context.
  • Record test hardening: unique sandbox directories per test (timestamp+pid) and making app_dir() override test-friendly (re-entrant).
  • Updated README.md and CHANGELOG.md accordingly. All tests pass locally.

umpire274 and others added 4 commits November 7, 2025 14:37
…test hardening & docs

- Implement atomic writes for the shared JSON cache (write to a temporary file in the same directory and replace via rename).
- Use advisory file locks (fs2) to protect concurrent access; added an open_and_lock() helper to centralize locking logic.
- Ensure the cache file lock is released and the handle closed before attempting rename/remove (fixes Windows “file in use” errors).
- Add a Windows fallback that attempts remove+rename when rename fails on older semantics.
- Make app_dir() test override re-entrant (OnceLock<Mutex<Option<pathbuf>>>) and harden tests by using unique sandbox directories (timestamp+pid) and ensuring source files exist before cache writes — fixes intermittent CI/test races.</pathbuf>
- Switch internal cache helper error handling to anyhow::Result for richer context.
- Update docs: README.md and CHANGELOG.md to document these changes.
- Add dependencies: fs2 and anyhow in Cargo.toml.
- Files changed (high level): src/utils.rs, src/config.rs, test files (tests/*), README.md, CHANGELOG.md, Cargo.toml.
All tests pass locally.
- Replace shared JSON cache with per-file .cache files (get_cache_path)

- Remove last_quotes.json and duplicated load_last_cache

- Use advisory locking via open_and_lock() for safe reads/writes

- Add thread-local app_dir override (set_app_dir_for_tests) and stable thread id hashing

- Remove debug prints and cleanup unused imports

- Tests: cargo test --all (all green)
@umpire274 umpire274 merged commit 5e3f1a8 into main Nov 10, 2025
1 check passed
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