From: Joerg Behrmann Date: Fri, 16 Sep 2022 16:15:11 +0000 (+0200) Subject: refactor mount_cache for better readability X-Git-Tag: v14~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04aadae781b4da7e56e58c22db0614cf17061e6c;p=thirdparty%2Fmkosi.git refactor mount_cache for better readability --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 1b42a4ed8..a816a7491 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1611,25 +1611,27 @@ def mount_api_vfs(root: Path) -> Iterator[None]: @contextlib.contextmanager def mount_cache(state: MkosiState) -> Iterator[None]: + if state.config.distribution in (Distribution.fedora, Distribution.mageia, Distribution.openmandriva): + cache_paths = ["var/cache/dnf"] + elif is_centos_variant(state.config.distribution): + # We mount both the YUM and the DNF cache in this case, as YUM might + # just be redirected to DNF even if we invoke the former + cache_paths = ["var/cache/yum", "var/cache/dnf"] + elif state.config.distribution in (Distribution.debian, Distribution.ubuntu): + cache_paths = ["var/cache/apt/archives"] + elif state.config.distribution == Distribution.arch: + cache_paths = ["var/cache/pacman/pkg"] + elif state.config.distribution == Distribution.gentoo: + cache_paths = ["var/cache/binpkgs"] + elif state.config.distribution == Distribution.opensuse: + cache_paths = ["var/cache/zypp/packages"] + else: + cache_paths = [] + # We can't do this in mount_image() yet, as /var itself might have to be created as a subvolume first with complete_step("Mounting Package Cache", "Unmounting Package Cache"), contextlib.ExitStack() as stack: - if state.config.distribution in (Distribution.fedora, Distribution.mageia, Distribution.openmandriva): - stack.enter_context(mount_bind(state.cache, state.root / "var/cache/dnf")) - elif is_centos_variant(state.config.distribution): - # We mount both the YUM and the DNF cache in this case, as - # YUM might just be redirected to DNF even if we invoke - # the former - stack.enter_context(mount_bind(state.cache / "yum", state.root / "var/cache/yum")) - stack.enter_context(mount_bind(state.cache / "dnf", state.root / "var/cache/dnf")) - elif state.config.distribution in (Distribution.debian, Distribution.ubuntu): - stack.enter_context(mount_bind(state.cache, state.root / "var/cache/apt/archives")) - elif state.config.distribution == Distribution.arch: - stack.enter_context(mount_bind(state.cache, state.root / "var/cache/pacman/pkg")) - elif state.config.distribution == Distribution.gentoo: - stack.enter_context(mount_bind(state.cache, state.root / "var/cache/binpkgs")) - elif state.config.distribution == Distribution.opensuse: - stack.enter_context(mount_bind(state.cache, state.root / "var/cache/zypp/packages")) - + for cache_path in cache_paths: + stack.enter_context(mount_bind(state.cache, state.root / cache_path)) yield