commit: 44d713565ee89e990ac10a438fef1126e47330b1 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Thu Dec 28 11:22:29 2023 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Sat Dec 30 16:19:10 2023 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=44d71356
dist-kernel-utils.eclass: Add dist-kernel_compressed_module_cleanup Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> eclass/dist-kernel-utils.eclass | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass index 67cb802151b2..8ccffd038474 100644 --- a/eclass/dist-kernel-utils.eclass +++ b/eclass/dist-kernel-utils.eclass @@ -210,5 +210,42 @@ dist-kernel_PV_to_KV() { echo "${kv}" } +# @FUNCTION: dist-kernel_compressed_module_cleanup +# @USAGE: <path> +# @DESCRIPTION: +# Traverse path for duplicate (un)compressed modules and remove all +# but the newest variant. +dist-kernel_compressed_module_cleanup() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${#} -ne 1 ]] && die "${FUNCNAME}: invalid arguments" + local path=${1} + local basename f + + while read -r basename; do + local prev= + for f in "${path}/${basename}"{,.gz,.xz,.zst}; do + if [[ ! -e ${f} ]]; then + continue + elif [[ -z ${prev} ]]; then + prev=${f} + elif [[ ${f} -nt ${prev} ]]; then + rm -v "${prev}" || die + prev=${f} + else + rm -v "${f}" || die + fi + done + done < <( + cd "${path}" && + find -type f \ + \( -name '*.ko' \ + -o -name '*.ko.gz' \ + -o -name '*.ko.xz' \ + -o -name '*.ko.zst' \ + \) | sed -e 's:[.]\(gz\|xz\|zst\)$::' | sort | uniq -d || die + ) +} + _DIST_KERNEL_UTILS=1 fi