Make 'nvd history' ignore broken profile symlinks (fixes #20).

This commit is contained in:
Bryan Gardiner 2024-11-03 17:13:31 -08:00
parent 734da23492
commit 6118dc1168
No known key found for this signature in database
GPG key ID: 53EFBCA063E6183C
2 changed files with 10 additions and 1 deletions

View file

@ -2,6 +2,9 @@
## 0.2.5 (unreleased)
- Fixed `nvd history` to ignore broken profile symlinks in case they were
forcably removed somehow (issue #20).
- Improve the error message when calling `nvd list`, and `/run/current-system`
doesn't exist (issue #21).

View file

@ -915,7 +915,13 @@ def is_link_to_profile(path: Path, profile_name: str) -> bool:
def make_profile_generation_list(profile_link: Path, minimum_version: int) -> List[ProfileVersion]:
profile_name = PROFILE_LINK_REGEX.match(str(profile_link)).group("profile")
all_profile_links = [l for l in profile_link.parent.iterdir() if is_link_to_profile(l, profile_name)]
# Use exists() to filter out broken symlinks, which has been reported to happen
# either with `home-manager expire-generations` or `nix profile wipe-history`
# (on Darwin with the DetSys installer in case that's relevant, see issue #20).
all_profile_links = [
l for l in profile_link.parent.iterdir()
if is_link_to_profile(l, profile_name) and l.exists()
]
all_profile_versions = [ProfileVersion(l) for l in all_profile_links]
all_profile_versions.sort()
profile_versions = [pv for pv in all_profile_versions if pv.version() >= minimum_version]