refactor(core): unify repository registry management and atomic file operations - #82
Merged
Merged
Conversation
…operations - Add add_repo_to_registry, remove_repo_from_registry, and write_registered_repos in system.py - Enhance get_registered_repos with dynamic registry path support and locking - Replace ad-hoc registry file manipulations and locking in daemon.py and cli.py - Remove redundant fcntl imports from daemon.py and cli.py - Add unit tests for registry operations and error handling in test_system.py
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.
Summary
This PR consolidates repository registry file operations and concurrency locking into a centralized, thread-safe, and process-safe API in
system.py:Centralized Registry Management API:
get_registered_repos(registry_path: Path | None = None) -> list[Path]to evaluate the registry path dynamically and safely handle non-existent files.add_repo_to_registry(repo_path: Path | str, registry_path: Path | None = None) -> boolfor atomic path registration withfcntl.LOCK_EXand duplicate prevention.remove_repo_from_registry(repo_path: Path | str, registry_path: Path | None = None) -> boolfor atomic path removal withfcntl.LOCK_EX,.tmpswap, andos.fsync.write_registered_repos(repos: Sequence[Path | str], registry_path: Path | None = None) -> boolfor atomic full-registry overwrites (used by doctor cleanup).Refactored Callers:
daemon.prune_registry: Simplified from ~40 lines of manual locking/swapping to a concise call tosystem.remove_repo_from_registry.cli.setup_repo: Simplified registration logic usingsystem.add_repo_to_registry.cli.unregister_repo: Simplified removal logic usingsystem.remove_repo_from_registry.cli.doctorandcli.diagnostics: Replaced raw file reads and writes withsystem.write_registered_reposandsystem.get_registered_repos.import fcntlfromdaemon.pyandcli.py.Automated Tests:
tests/test_system.pycovering path addition, deduplication, removal, atomic writing, andOSErrorresilience.tests/test_properties.py.Verification
ruff check,ruff format,mypy) passing cleanly.