Skip to content

Commit

Permalink
apport-retrace: install base-files first
Browse files Browse the repository at this point in the history
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" <<EOF
deb http://de.archive.ubuntu.com/ubuntu/ noble main universe
deb-src http://de.archive.ubuntu.com/ubuntu/ noble main universe
EOF
$ apport-retrace -v -S "$PWD/sandbox-config" --gdb-sandbox -C "$PWD/sandbox-cache" /var/crash/_usr_bin_divide-by-zero.1000.crash
[...]
Extracting downloaded debs...
ERROR: [Errno 2] No such file or directory: '/tmp/apport_sandbox_8x704zqr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2'
```

Bug-Ubuntu: https://launchpad.net/bugs/2067120
  • Loading branch information
bdrung authored and schopin-pro committed Jun 7, 2024
1 parent 7a40931 commit 52560e6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
14 changes: 14 additions & 0 deletions apport/sandboxutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ def needed_runtime_packages(report, pkgmap_cache_dir, pkg_versions, verbose=Fals
return [(p, pkg_versions.get(p)) for p in pkgs]


def _move_or_add_base_files_first(pkgs: list[tuple[str, None | str]]) -> 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,
Expand Down Expand Up @@ -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(
Expand Down
35 changes: 34 additions & 1 deletion tests/unit/test_sandboxutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"),
],
)

0 comments on commit 52560e6

Please sign in to comment.