From: Daan De Meyer Date: Wed, 24 Jul 2024 10:48:42 +0000 (+0200) Subject: Don't copy /var/lib/pacman/local when copying repository metadata X-Git-Tag: v24~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6fe17de67ad69df04dd7996540f90753a332fbe;p=thirdparty%2Fmkosi.git Don't copy /var/lib/pacman/local when copying repository metadata /var/lib/pacman/local contains the local database of installed packages. When using "--package-cache-dir /var", we'd end up copying the local database of the host which means pacman thinks packages are already installed in the image even though they aren't. Fix this by not copying /var/lib/pacman/local. Fixes #2904 --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 29b4d2c22..cf201065f 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -3832,17 +3832,21 @@ def copy_repository_metadata(context: Context) -> None: logging.debug(f"{src} does not exist, not copying repository metadata from it") continue - if d == "cache": - caches = context.config.distribution.package_manager(context.config).cache_subdirs(src) - else: - caches = [] - with tempfile.TemporaryDirectory() as tmp: os.chmod(tmp, 0o755) # cp doesn't support excluding directories but we can imitate it by bind mounting an empty directory # over the directories we want to exclude. - exclude = [Mount(tmp, p, ro=True) for p in caches] + if d == "cache": + exclude = [ + Mount(tmp, p, ro=True) + for p in context.config.distribution.package_manager(context.config).cache_subdirs(src) + ] + else: + exclude = [ + Mount(tmp, p, ro=True) + for p in context.config.distribution.package_manager(context.config).state_subdirs(src) + ] dst = context.package_cache_dir / d / subdir with umask(~0o755): diff --git a/mkosi/installer/__init__.py b/mkosi/installer/__init__.py index 74d05d1d7..0f28d3e73 100644 --- a/mkosi/installer/__init__.py +++ b/mkosi/installer/__init__.py @@ -25,6 +25,10 @@ class PackageManager: def cache_subdirs(cls, cache: Path) -> list[Path]: return [] + @classmethod + def state_subdirs(cls, state: Path) -> list[Path]: + return [] + @classmethod def scripts(cls, context: Context) -> dict[str, list[PathString]]: return {} diff --git a/mkosi/installer/pacman.py b/mkosi/installer/pacman.py index b3219a917..ea0c4abf4 100644 --- a/mkosi/installer/pacman.py +++ b/mkosi/installer/pacman.py @@ -35,6 +35,10 @@ class Pacman(PackageManager): def cache_subdirs(cls, cache: Path) -> list[Path]: return [cache / "pkg"] + @classmethod + def state_subdirs(cls, state: Path) -> list[Path]: + return [state / "local"] + @classmethod def scripts(cls, context: Context) -> dict[str, list[PathString]]: return {