From 6118dc11682531eced90f686cacf11f7a7f95f6d Mon Sep 17 00:00:00 2001 From: Bryan Gardiner Date: Sun, 3 Nov 2024 17:13:31 -0800 Subject: [PATCH] Make 'nvd history' ignore broken profile symlinks (fixes #20). --- CHANGELOG.md | 3 +++ src/nvd | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f59bba..3d0c3f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/src/nvd b/src/nvd index c68390d..1cc429c 100755 --- a/src/nvd +++ b/src/nvd @@ -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]