# cp doesn't support excluding directories but we can imitate it by bind mounting
# an empty directory over the directories we want to exclude.
exclude = flatten(
- ("--ro-bind", tmp, workdir(cachedir / p))
- for p in config.distribution.package_manager(config).package_subdirs(cachedir)
+ ("--ro-bind", tmp, workdir(cachedir / srcsubdir))
+ for srcsubdir, _ in config.distribution.package_manager(config).package_subdirs(cachedir)
)
subdst = dst / "cache" / subdir
)
src = last.package_cache_dir_or_default() / "cache" / subdir
- for p in last.distribution.package_manager(last).package_subdirs(src):
- (src / p).mkdir(parents=True, exist_ok=True)
+ for srcsubdir, _ in last.distribution.package_manager(last).package_subdirs(src):
+ (src / srcsubdir).mkdir(parents=True, exist_ok=True)
# If we're in incremental mode and caching metadata is not explicitly disabled, cache the keyring and the
# synced repository metadata so we can reuse them later.
return Path("custom")
@classmethod
- def package_subdirs(cls, cache: Path) -> list[Path]:
+ def package_subdirs(cls, cache: Path) -> list[tuple[Path, Path]]:
return []
@classmethod
mounts += flatten(
(
"--bind",
- context.config.package_cache_dir_or_default() / d / subdir / p,
- Path("/var") / d / subdir / p,
+ context.config.package_cache_dir_or_default() / d / subdir / srcsubdir,
+ Path("/var") / d / subdir / dstsubdir,
)
- for p in caches
- if (
- context.config.package_cache_dir_or_default() / d / subdir / p
- ).exists()
+ for srcsubdir, dstsubdir in caches
+ if (context.config.package_cache_dir_or_default() / d / subdir / srcsubdir).exists()
)
return mounts
return Path("apt")
@classmethod
- def package_subdirs(cls, cache: Path) -> list[Path]:
- return [Path("archives")]
+ def package_subdirs(cls, cache: Path) -> list[tuple[Path, Path]]:
+ return [(Path("archives"), Path("archives"))]
@classmethod
def state_subdirs(cls, state: Path) -> list[Path]:
return Path("libdnf5" if cls.executable(config) == "dnf5" else "dnf")
@classmethod
- def package_subdirs(cls, cache: Path) -> list[Path]:
+ def package_subdirs(cls, cache: Path) -> list[tuple[Path, Path]]:
+ dirs = [p for p in cache.iterdir() if p.is_dir() and "-" in p.name and "mkosi" not in p.name]
return [
- (p / "packages").relative_to(cache) for p in cache.iterdir() if p.is_dir() and "-" in p.name and "mkosi" not in p.name
+ (
+ d.relative_to(cache) / "packages"
+ if cache == Path("/var")
+ # Cache directories look like <repo-id>-<baseurl-hash> so let's strip off the hash to reuse
+ # the same package cache directory regardless of baseurl.
+ else Path("packages") / d.name[: d.name.rfind("-")],
+ d.relative_to(cache) / "packages",
+ )
+ for d in dirs
]
@classmethod
return Path("pacman")
@classmethod
- def package_subdirs(cls, cache: Path) -> list[Path]:
- return [Path("pkg")]
+ def package_subdirs(cls, cache: Path) -> list[tuple[Path, Path]]:
+ return [(Path("pkg"), Path("pkg"))]
@classmethod
def state_subdirs(cls, state: Path) -> list[Path]:
return Path("zypp")
@classmethod
- def package_subdirs(cls, cache: Path) -> list[Path]:
- return [Path("packages")]
+ def package_subdirs(cls, cache: Path) -> list[tuple[Path, Path]]:
+ return [(Path("packages"), Path("packages"))]
@classmethod
def scripts(cls, context: Context) -> dict[str, list[PathString]]: