diff options
author | Michał Górny <mgorny@gentoo.org> | 2023-12-28 12:22:29 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2023-12-30 17:19:10 +0100 |
commit | 44d713565ee89e990ac10a438fef1126e47330b1 (patch) | |
tree | deba92576f1d814e7cd29478d29ef1d8d4d8b00a /eclass/dist-kernel-utils.eclass | |
parent | linux-mod.eclass: Fix xz compression options (diff) | |
download | gentoo-44d713565ee89e990ac10a438fef1126e47330b1.tar.gz gentoo-44d713565ee89e990ac10a438fef1126e47330b1.tar.bz2 gentoo-44d713565ee89e990ac10a438fef1126e47330b1.zip |
dist-kernel-utils.eclass: Add dist-kernel_compressed_module_cleanup
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass/dist-kernel-utils.eclass')
-rw-r--r-- | eclass/dist-kernel-utils.eclass | 37 |
1 files changed, 37 insertions, 0 deletions
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 |