From: Daan De Meyer Date: Fri, 26 Sep 2025 13:46:22 +0000 (+0200) Subject: apk: Always operate on package cache directory X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=53e9d16e800f8ef58bf994026f51550934563475;p=thirdparty%2Fmkosi.git apk: Always operate on package cache directory 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. --- diff --git a/mkosi/installer/__init__.py b/mkosi/installer/__init__.py index 5eeccfe8e..da8fa4db6 100644 --- a/mkosi/installer/__init__.py +++ b/mkosi/installer/__init__.py @@ -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 diff --git a/mkosi/installer/apk.py b/mkosi/installer/apk.py index e39b52c7f..9c9b754fa 100644 --- a/mkosi/installer/apk.py +++ b/mkosi/installer/apk.py @@ -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 {