]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
apk: Always operate on package cache directory 3918/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 26 Sep 2025 13:46:22 +0000 (15:46 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 27 Sep 2025 12:18:21 +0000 (14:18 +0200)
apk does not use any subdirectories under /var/cache/apk to store
packages, which means that our usual tricks to mount package cache
directories from the package cache directory and repository metadata
from the metadata cache directory into the expected locations don't work.

There might be a way to get this to work with overlayfs but this would
be a very complex change. Instead, let's just disable repository metadata
caching for apk and always use the package cache directory for everything.

mkosi/installer/__init__.py
mkosi/installer/apk.py

index 5eeccfe8edfda3c8cafd3a215a3c641c4ef6cb89..da8fa4db604e3dddab99bcd3f8472ad73d60b11d 100644 (file)
@@ -76,24 +76,38 @@ class PackageManager:
 
         subdir = context.config.distribution.package_manager(context.config).subdir(context.config)
 
-        for d in ("cache", "lib"):
-            src = context.metadata_dir / d / subdir
-            mounts += ["--bind", src, Path("/var") / d / subdir]
+        src = context.metadata_dir / "lib" / subdir
+        mounts += ["--bind", src, Path("/var/lib") / subdir]
+
+        src = context.metadata_dir / "cache" / subdir
+        caches = context.config.distribution.package_manager(context.config).package_subdirs(src)
+
+        # If there are no package cache subdirectories, we always operate on the package cache directory,
+        # since we can't do any mount tricks to combine caches from different locations in this case.
+        if caches == [(Path("."), Path("."))]:
+            mounts += [
+                "--bind",
+                context.config.package_cache_dir_or_default() / "cache" / subdir,
+                Path("/var/cache") / subdir,
+            ]
+        else:
+            mounts += ["--bind", src, Path("/var/cache") / subdir]
 
             # If we're not operating on the configured package cache directory, we're operating on a snapshot
             # of the repository metadata. To make sure any downloaded packages are still cached in the
             # configured package cache directory in this scenario, we mount in the relevant directories from
             # the configured package cache directory.
-            if d == "cache" and context.metadata_dir != context.config.package_cache_dir_or_default():
-                caches = context.config.distribution.package_manager(context.config).package_subdirs(src)
+            if context.metadata_dir != context.config.package_cache_dir_or_default():
                 mounts += flatten(
                     (
                         "--bind",
-                        context.config.package_cache_dir_or_default() / d / subdir / srcsubdir,
-                        Path("/var") / d / subdir / dstsubdir,
+                        context.config.package_cache_dir_or_default() / "cache" / subdir / srcsubdir,
+                        Path("/var/cache") / subdir / dstsubdir,
                     )
                     for srcsubdir, dstsubdir in caches
-                    if (context.config.package_cache_dir_or_default() / d / subdir / srcsubdir).exists()
+                    if (
+                        context.config.package_cache_dir_or_default() / "cache" / subdir / srcsubdir
+                    ).exists()
                 )
 
         return mounts
index e39b52c7fed64589a3286e3ff898ffb5008682e7..9c9b754fad56720e66e3c21f1a03ed70705753b6 100644 (file)
@@ -27,6 +27,10 @@ class Apk(PackageManager):
     def subdir(cls, config: Config) -> Path:
         return Path("apk")
 
+    @classmethod
+    def package_subdirs(cls, cache: Path) -> list[tuple[Path, Path]]:
+        return [(Path("."), Path("."))]
+
     @classmethod
     def scripts(cls, context: Context) -> dict[str, list[PathString]]:
         return {