]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use package manager specific subdirectories in the cache directory
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 8 Nov 2023 11:29:39 +0000 (12:29 +0100)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Wed, 8 Nov 2023 11:53:01 +0000 (12:53 +0100)
We want to be able to set --cache-dir=/var/cache to automatically
reuse the system cache for each installed package manager, so let's
make sure we use the right subdirectories for each package manager
to make that work properly.

mkosi/installer/apt.py
mkosi/installer/dnf.py
mkosi/installer/pacman.py
mkosi/installer/zypper.py

index 0a7472812aa0b47c7222646ce3c047c00920fbfb..4a5157af6093edda73ec4df6fc4037c58ed624ef 100644 (file)
@@ -81,7 +81,7 @@ def apt_cmd(state: MkosiState, command: str) -> list[PathString]:
         "-o", "APT::Get::Allow-Change-Held-Packages=true",
         "-o", "APT::Get::Allow-Remove-Essential=true",
         "-o", "APT::Sandbox::User=root",
-        "-o", f"Dir::Cache={state.cache_dir}",
+        "-o", f"Dir::Cache={state.cache_dir / 'apt'}",
         "-o", f"Dir::State={state.pkgmngr / 'var/lib/apt'}",
         "-o", f"Dir::State::status={state.root / 'var/lib/dpkg/status'}",
         "-o", f"Dir::Etc::trusted={trustedkeys}",
index 79a51720a534393209ae068cbaa3f1fe8d88bd64..1ba0c2e898689b8fc4623bd0b9cb1738f6378cfa 100644 (file)
@@ -106,7 +106,7 @@ def dnf_cmd(state: MkosiState) -> list[PathString]:
         f"--releasever={state.config.release}",
         f"--installroot={state.root}",
         "--setopt=keepcache=1",
-        f"--setopt=cachedir={state.cache_dir}",
+        f"--setopt=cachedir={state.cache_dir / ('libdnf5' if dnf.endswith('dnf5') else 'dnf')}",
         f"--setopt=reposdir={state.pkgmngr / 'etc/yum.repos.d'}",
         f"--setopt=varsdir={state.pkgmngr / 'etc/dnf/vars'}",
         f"--setopt=persistdir={state.pkgmngr / 'var/lib/dnf'}",
index 621a2cc10915ad61e3ad5e31092f5a2a271f1668..e96d7e280511187300eb5f8aca0ff44cc6768d24 100644 (file)
@@ -87,12 +87,15 @@ def pacman_cmd(state: MkosiState) -> list[PathString]:
     gpgdir = state.pkgmngr / "etc/pacman.d/gnupg/"
     gpgdir = gpgdir if gpgdir.exists() else Path("/etc/pacman.d/gnupg/")
 
+    with umask(~0o755):
+        (state.cache_dir / "pacman/pkg").mkdir(parents=True, exist_ok=True)
+
     cmdline: list[PathString] = [
         "pacman",
         "--config", state.pkgmngr / "etc/pacman.conf",
         "--root", state.root,
         "--logfile=/dev/null",
-        "--cachedir", state.cache_dir,
+        "--cachedir", state.cache_dir / "pacman/pkg",
         "--gpgdir", gpgdir,
         "--hookdir", state.root / "etc/pacman.d/hooks",
         "--arch", state.config.distribution.architecture(state.config.architecture),
index 38b35a6550513baab4bd2e292bcfacd3843b5070..487541e82c97952ebdde61a8ffcf532f7805df24 100644 (file)
@@ -55,7 +55,7 @@ def zypper_cmd(state: MkosiState) -> list[PathString]:
         f"ZYPP_CONF={state.pkgmngr / 'etc/zypp/zypp.conf'}",
         "zypper",
         f"--root={state.root}",
-        f"--cache-dir={state.cache_dir}",
+        f"--cache-dir={state.cache_dir / 'zypp'}",
         f"--reposd-dir={state.pkgmngr / 'etc/zypp/repos.d'}",
         "--gpg-auto-import-keys" if state.config.repository_key_check else "--no-gpg-checks",
         "--non-interactive",