From 52560e691cb140ad37b3bf147e17a4d6fdbd2029 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Fri, 7 Jun 2024 12:09:15 +0200 Subject: [PATCH] apport-retrace: install base-files first On Ubuntu 24.04 (noble): ``` $ divide-by-zero $ mkdir -p "$PWD/sandbox-config/Ubuntu 24.04" $ echo noble > "$PWD/sandbox-config/Ubuntu 24.04/codename" $ cat > "$PWD/sandbox-config/Ubuntu 24.04/sources.list" < None: + """Move base-files to the front or add it if missing.""" + base_files_version = None + for i, (pkg, version) in enumerate(pkgs): + if pkg == "base-files": + base_files_version = version + pkgs.pop(i) + break + pkgs[:0] = [("base-files", base_files_version)] + + # pylint: disable-next=too-many-arguments def make_sandbox( report: apport.Report, @@ -222,6 +233,9 @@ def make_sandbox( if origins: apport.logging.log(f"Origins: {origins}") + # Install base-files first to get correct usrmerge + _move_or_add_base_files_first(pkgs) + # unpack packages, if any, using cache and sandbox try: outdated_msg = packaging.install_packages( diff --git a/tests/unit/test_sandboxutils.py b/tests/unit/test_sandboxutils.py index 791f92249..bdb933613 100644 --- a/tests/unit/test_sandboxutils.py +++ b/tests/unit/test_sandboxutils.py @@ -17,7 +17,7 @@ from apport.packaging import PackageInfo from apport.report import Report -from apport.sandboxutils import make_sandbox +from apport.sandboxutils import _move_or_add_base_files_first, make_sandbox class TestSandboxutils(unittest.TestCase): @@ -71,3 +71,36 @@ def test_make_sandbox_with_sandbox_dir(self, packaging_mock: MagicMock) -> None: self.assertEqual(cache, cache_dir) self.assertEqual(outdated_msg, "obsolete\nobsolete\n") self.assertEqual(packaging_mock.install_packages.call_count, 2) + + def test_move_or_add_base_files_first_existing(self) -> None: + """_move_or_add_base_files_first() with base-files in list.""" + pkgs: list[tuple[str, None | str]] = [ + ("chaos-marmosets", "0.1.2-2"), + ("base-files", "13ubuntu9"), + ("libc6", "2.39-0ubuntu8.2"), + ] + _move_or_add_base_files_first(pkgs) + self.assertEqual( + pkgs, + [ + ("base-files", "13ubuntu9"), + ("chaos-marmosets", "0.1.2-2"), + ("libc6", "2.39-0ubuntu8.2"), + ], + ) + + def test_move_or_add_base_files_first_missing(self) -> None: + """_move_or_add_base_files_first() without base-files in list.""" + pkgs: list[tuple[str, None | str]] = [ + ("chaos-marmosets", "0.1.2-2"), + ("libc6", "2.39-0ubuntu8.2"), + ] + _move_or_add_base_files_first(pkgs) + self.assertEqual( + pkgs, + [ + ("base-files", None), + ("chaos-marmosets", "0.1.2-2"), + ("libc6", "2.39-0ubuntu8.2"), + ], + )