# (which are often used as a base tree for extension images and thus should retain package manager metadata) or if
# the corresponding package manager is installed in the image.
- always = context.config.clean_package_metadata == ConfigFeature.enabled
executable = context.config.distribution.package_manager(context.config).executable(context.config)
for tool, paths in (("rpm", ["var/lib/rpm", "usr/lib/sysimage/rpm"]),
("dnf5", ["usr/lib/sysimage/libdnf5"]),
("dpkg", ["var/lib/dpkg"]),
(executable, [f"var/lib/{subdir}", f"var/cache/{subdir}"])):
- if always or not find_binary(tool, root=context.root):
+ if context.config.clean_package_metadata == ConfigFeature.enabled or not find_binary(tool, root=context.root):
rmtree(*(context.root / p for p in paths if (context.root / p).exists()), sandbox=context.sandbox)