[4/8] rootfs: split clean_package_cache command

Message ID 20260820083014.3377283-5-felix.moessbauer@siemens.com
State New
Headers show
Series Make all sstate artifacts reproducible | expand

Commit Message

Felix Moessbauer Aug. 20, 2026, 8:30 a.m. UTC
We currently also delete the apt lists in /var/lib/apt in that command,
but this requires a later user of the chroot to run apt-update again
(with all its implications). To avoid that, but still be able to clean
the apt cache for reproducability reasons, we split the command into the
purging of the cache and a new one "clean_apt_lists" that remove the apt
lists.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes-recipe/image.bbclass  |  1 +
 meta/classes-recipe/rootfs.bbclass | 10 ++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

Patch

diff --git a/meta/classes-recipe/image.bbclass b/meta/classes-recipe/image.bbclass
index a749441f..f3a27782 100644
--- a/meta/classes-recipe/image.bbclass
+++ b/meta/classes-recipe/image.bbclass
@@ -95,6 +95,7 @@  inherit essential
 ROOTFSDIR = "${IMAGE_ROOTFS}"
 ROOTFS_FEATURES += "\
     clean-package-cache \
+    clean-apt-lists \
     clean-pycache \
     generate-manifest \
     export-dpkg-status \
diff --git a/meta/classes-recipe/rootfs.bbclass b/meta/classes-recipe/rootfs.bbclass
index e67a0214..79dec69f 100644
--- a/meta/classes-recipe/rootfs.bbclass
+++ b/meta/classes-recipe/rootfs.bbclass
@@ -31,6 +31,7 @@  ROOTFS_BASE_DISTRO ?= "${BASE_DISTRO}"
 # available features are:
 # 'clean-package-cache' - delete package cache from rootfs
 # 'clean-debconf-cache' - delete debconf cache files
+# 'clean-apt-lists' - delete apt lists files (after execution, apt-get update needs to be run again)
 # 'clean-pycache' - delete python bytecode cache files
 # 'generate-manifest' - generate a package manifest of the rootfs into ${ROOTFS_MANIFEST_DEPLOY_DIR}
 # 'generate-sbom' - generate a SBOM of the rootfs into ${DEPLOY_DIR_SBOM}
@@ -522,9 +523,14 @@  ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'clean-pa
 rootfs_postprocess_clean_package_cache() {
     run_in_chroot '${ROOTFSDIR}' \
         /usr/bin/apt-get clean
-    run_privileged rm -rf "${ROOTFSDIR}/var/lib/apt/lists/"*
     # remove apt-cache folder itself (required in case rootfs is provided by sstate cache)
-    run_privileged rm -rf "${ROOTFSDIR}/var/cache/apt/archives"
+    run_privileged find "${ROOTFSDIR}/var/cache/apt" -type f \
+        \( -name '*.deb' -o -name '*.bin' \) -delete
+}
+
+ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'clean-apt-lists', 'rootfs_postprocess_clean_apt_lists', '', d)}"
+rootfs_postprocess_clean_apt_lists() {
+    run_privileged find "${ROOTFSDIR}/var/lib/apt/lists" -type f -delete
 }
 
 ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'clean-log-files', 'rootfs_postprocess_clean_log_files', '', d)}"