]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Make sure we cache state from package managers as well 2212/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 22 Dec 2023 14:39:44 +0000 (15:39 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 22 Dec 2023 14:54:28 +0000 (15:54 +0100)
To do this we start using cache/ and lib/ directories underneath
the cache directory.

We also fix our cleanup logic to only remove the relevant directories
in case the cache directory is configured to be /var or similar.

kernel-install/50-mkosi.install
mkosi/__init__.py
mkosi/installer/apt.py
mkosi/installer/dnf.py
mkosi/installer/pacman.py
mkosi/installer/zypper.py

index 0f9e9e3867418956b137565e37dd71c6e1d0631a..ca19fe48f6a264655c8a9c6b0f1d120964635538 100644 (file)
@@ -104,7 +104,7 @@ def main() -> None:
         "--format", str(format),
         "--output", output,
         "--workspace-dir=/var/tmp",
-        "--cache-dir=/var/cache",
+        "--cache-dir=/var",
         "--output-dir", context.staging_area,
         "--extra-tree", f"/usr/lib/modules/{context.kernel_version}:/usr/lib/modules/{context.kernel_version}",
         "--extra-tree=/usr/lib/firmware:/usr/lib/firmware",
index c0f60dda2a8d7a2a2a3e1b02cabdc66c4c0f8e23..9ed6b50fa9abc392ca8ae3630b82b301ec9a3eff 100644 (file)
@@ -1921,7 +1921,11 @@ def unlink_output(args: MkosiArgs, config: MkosiConfig) -> None:
     if remove_package_cache:
         if config.cache_dir and config.cache_dir.exists() and any(config.cache_dir.iterdir()):
             with complete_step("Clearing out package cache…"):
-                empty_directory(config.cache_dir)
+                rmtree(*(
+                    config.cache_dir / p / d
+                    for p in ("cache", "lib")
+                    for d in ("apt", "dnf", "libdnf5", "pacman", "zypp")
+                ))
 
 
 def cache_tree_paths(config: MkosiConfig) -> tuple[Path, Path, Path]:
index 9ccf001e20cabab28093fab8470e806a577bf738..e14fc95c5aa4b3ee2121b993d10bfef25ad18495 100644 (file)
@@ -20,6 +20,9 @@ def setup_apt(state: MkosiState, repos: Sequence[str]) -> None:
         (state.root / "var/lib/dpkg").mkdir(parents=True, exist_ok=True)
         (state.root / "var/lib/dpkg/status").touch()
 
+    (state.cache_dir / "lib/apt").mkdir(exist_ok=True, parents=True)
+    (state.cache_dir / "cache/apt").mkdir(exist_ok=True, parents=True)
+
     # We have a special apt.conf outside of pkgmngr dir that only configures "Dir::Etc" that we pass to APT_CONFIG to
     # tell apt it should read config files from /etc/apt in case this is overridden by distributions. This is required
     # because apt parses CLI configuration options after parsing its configuration files and as such we can't use CLI
@@ -65,8 +68,8 @@ 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 / 'apt'}",
-        "-o", f"Dir::State={state.cache_dir / 'apt'}",
+        "-o", f"Dir::Cache={state.cache_dir / 'cache/apt'}",
+        "-o", f"Dir::State={state.cache_dir / 'lib/apt'}",
         "-o", f"Dir::State::Status={state.root / 'var/lib/dpkg/status'}",
         "-o", f"Dir::Etc::Trusted={trustedkeys}",
         "-o", f"Dir::Log={state.workspace}",
index 90aa8f2b18d314faf2ac419e85f86f20b698f34b..58d609f0266c704c0fe50d86901503b8107835e1 100644 (file)
@@ -76,7 +76,8 @@ 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 / ('libdnf5' if dnf.endswith('dnf5') else 'dnf')}",
+        f"--setopt=cachedir={state.cache_dir / 'cache' / ('libdnf5' if dnf.endswith('dnf5') else 'dnf')}",
+        f"--setopt=persistdir={state.cache_dir / 'lib' / ('libdnf5' if dnf.endswith('dnf5') else 'dnf')}",
         f"--setopt=install_weak_deps={int(state.config.with_recommends)}",
         "--setopt=check_config_file_age=0",
         "--disable-plugin=*" if dnf.endswith("dnf5") else "--disableplugin=*",
@@ -107,7 +108,6 @@ def dnf_cmd(state: MkosiState) -> list[PathString]:
             "--config=/etc/dnf/dnf.conf",
             "--setopt=reposdir=/etc/yum.repos.d",
             "--setopt=varsdir=/etc/dnf/vars",
-            "--setopt=persistdir=/var/lib/dnf",
         ]
 
     return cmdline
index a822e8a50c3acdb90d0bf7acca81ca9efd2ac6ac..f0bbe30d6757289f5ea27008a6e55ad14f480948 100644 (file)
@@ -26,6 +26,8 @@ def setup_pacman(state: MkosiState, repositories: Iterable[PacmanRepository]) ->
     with umask(~0o755):
         (state.root / "var/lib/pacman").mkdir(exist_ok=True, parents=True)
 
+    (state.cache_dir / "cache/pacman/pkg").mkdir(parents=True, exist_ok=True)
+
     config = state.pkgmngr / "etc/pacman.conf"
     if config.exists():
         return
@@ -67,14 +69,11 @@ def setup_pacman(state: MkosiState, repositories: Iterable[PacmanRepository]) ->
 
 
 def pacman_cmd(state: MkosiState) -> list[PathString]:
-    with umask(~0o755):
-        (state.cache_dir / "pacman/pkg").mkdir(parents=True, exist_ok=True)
-
     return [
         "pacman",
         "--root", state.root,
         "--logfile=/dev/null",
-        "--cachedir", state.cache_dir / "pacman/pkg",
+        "--cachedir", state.cache_dir / "cache/pacman/pkg",
         "--hookdir", state.root / "etc/pacman.d/hooks",
         "--arch", state.config.distribution.architecture(state.config.architecture),
         "--color", "auto",
index c5b684cc23d47fe256f1304ab9a143d706e04ab0..7e2626bd4fa9c63b952a01b5597f42572d0e9350 100644 (file)
@@ -61,7 +61,7 @@ def zypper_cmd(state: MkosiState) -> list[PathString]:
         "HOME=/",
         "zypper",
         f"--installroot={state.root}",
-        f"--cache-dir={state.cache_dir / 'zypp'}",
+        f"--cache-dir={state.cache_dir / 'cache/zypp'}",
         "--gpg-auto-import-keys" if state.config.repository_key_check else "--no-gpg-checks",
         "--non-interactive",
     ]