]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Don't copy /var/lib/pacman/local when copying repository metadata
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 24 Jul 2024 10:48:42 +0000 (12:48 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 24 Jul 2024 14:17:50 +0000 (16:17 +0200)
/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

mkosi/__init__.py
mkosi/installer/__init__.py
mkosi/installer/pacman.py

index 29b4d2c2250178aa263647e7c03aedb97107b7f4..cf201065fb7936139580d8bc07e4ead38d5c5d3c 100644 (file)
@@ -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):
index 74d05d1d70d775c13a5ec61cf0a9ab9d8902c1d8..0f28d3e730ec97fb2c1d7c604da2765ad4a42f45 100644 (file)
@@ -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 {}
index b3219a9172a40f9f9fc91e373b3e987613297ed4..ea0c4abf4f92b804f27b1498d34aeca8f6668905 100644 (file)
@@ -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 {