From 1ae55377eace43d5e0c8429c570ea7c5fed35410 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 31 Jul 2025 22:48:02 -0700 Subject: [PATCH] distupgrade: Handle comments in sources.list file Tests: - Add a comment and /etc/apt/sources.list file. Distribution upgrade page does not load and fails with an error. - With the patch, page loads properly. Distribution upgrade can be triggered. Signed-off-by: Sunil Mohan Adapa [jvalleroy: Fix test for release date] Signed-off-by: James Valleroy Reviewed-by: James Valleroy --- plinth/modules/upgrades/distupgrade.py | 3 +++ plinth/modules/upgrades/tests/test_distupgrade.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plinth/modules/upgrades/distupgrade.py b/plinth/modules/upgrades/distupgrade.py index 964ac66fa..d32aace94 100644 --- a/plinth/modules/upgrades/distupgrade.py +++ b/plinth/modules/upgrades/distupgrade.py @@ -116,6 +116,9 @@ def _get_sources_list_codename() -> str | None: dists = set() for match_ in aug.match('*'): dist = aug.get(match_ + '/distribution') + if not dist: + continue + dist = dist.removesuffix('-updates') dist = dist.removesuffix('-security') dists.add(dist) diff --git a/plinth/modules/upgrades/tests/test_distupgrade.py b/plinth/modules/upgrades/tests/test_distupgrade.py index 6484c9f6f..52f3cfaff 100644 --- a/plinth/modules/upgrades/tests/test_distupgrade.py +++ b/plinth/modules/upgrades/tests/test_distupgrade.py @@ -190,7 +190,7 @@ def test_get_status(check_auto, is_dist_upgrade_enabled, assert status['current_release_date'] == current_date assert status['next_codename'] == 'trixie' assert status['next_version'] == 13 - next_date = datetime_original(2025, 8, 20, tzinfo=timezone.utc) + next_date = datetime_original(2025, 8, 9, tzinfo=timezone.utc) assert status['next_release_date'] == next_date assert status['next_action'] == 'manual'