From: DaanDeMeyer Date: Sat, 5 Jul 2025 19:08:32 +0000 (+0200) Subject: pacman: Don't fail if packages to remove aren't installed X-Git-Tag: v26~186^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e7e75a3853353df69e902ae3b0eb2f4e817635c;p=thirdparty%2Fmkosi.git pacman: Don't fail if packages to remove aren't installed We already do this for other package managers, let's do it for pacman as well. --- diff --git a/mkosi/installer/pacman.py b/mkosi/installer/pacman.py index 55b34f0f9..9d6343b1c 100644 --- a/mkosi/installer/pacman.py +++ b/mkosi/installer/pacman.py @@ -198,7 +198,12 @@ class Pacman(PackageManager): @classmethod def remove(cls, context: Context, packages: Sequence[str]) -> None: - cls.invoke(context, "--remove", ["--nosave", "--recursive", *packages], apivfs=True) + installed = { + cls.parse_pkg_desc(i)[0] for i in (context.root / "var/lib/pacman/local").glob("*/desc") + } + remove = [p for p in packages if p in installed] + if remove: + cls.invoke(context, "--remove", ["--nosave", "--recursive", *remove], apivfs=True) @classmethod def keyring(cls, context: Context) -> None: @@ -262,3 +267,22 @@ class Pacman(PackageManager): # pacman can't sync a single repository, so we go behind its back and do it ourselves. shutil.move(context.repository / "mkosi.db.tar", context.metadata_dir / "lib/pacman/sync/mkosi.db") + + @classmethod + def parse_pkg_desc(cls, path: Path) -> tuple[str, str, str, str]: + name = version = base = arch = "" + + with path.open() as desc: + for line in desc: + line = line.strip() + if line == "%NAME%": + name = next(desc).strip() + elif line == "%VERSION%": + version = next(desc).strip() + elif line == "%BASE%": + base = next(desc).strip() + elif line == "%ARCH%": + arch = next(desc).strip() + break + + return name, version, base, arch diff --git a/mkosi/manifest.py b/mkosi/manifest.py index 90c485c25..56bdd16d8 100644 --- a/mkosi/manifest.py +++ b/mkosi/manifest.py @@ -5,13 +5,13 @@ import datetime import json import subprocess import textwrap -from pathlib import Path from typing import IO, Any, Optional from mkosi.config import ManifestFormat from mkosi.context import Context from mkosi.distributions import PackageType from mkosi.installer.apt import Apt +from mkosi.installer.pacman import Pacman from mkosi.log import complete_step from mkosi.run import run @@ -63,23 +63,6 @@ class SourcePackageManifest: return t -def parse_pkg_desc(f: Path) -> tuple[str, str, str, str]: - name = version = base = arch = "" - with f.open() as desc: - for line in desc: - line = line.strip() - if line == "%NAME%": - name = next(desc).strip() - elif line == "%VERSION%": - version = next(desc).strip() - elif line == "%BASE%": - base = next(desc).strip() - elif line == "%ARCH%": - arch = next(desc).strip() - break - return name, version, base, arch - - @dataclasses.dataclass class Manifest: context: Context @@ -221,7 +204,7 @@ class Manifest: packages = sorted((self.context.root / "var/lib/pacman/local").glob("*/desc")) for desc in packages: - name, version, source, arch = parse_pkg_desc(desc) + name, version, source, arch = Pacman.parse_pkg_desc(desc) package = PackageManifest("pkg", name, version, arch, 0) self.packages.append(package)