From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 284DB158015 for ; Thu, 28 Dec 2023 12:21:20 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E4A412BC050; Thu, 28 Dec 2023 12:21:14 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 9ADE02BC03A for ; Thu, 28 Dec 2023 12:21:14 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH 1/3] dist-kernel-utils.eclass: Add dist-kernel_compressed_module_cleanup Date: Thu, 28 Dec 2023 13:21:04 +0100 Message-ID: <20231228122106.1040252-1-mgorny@gentoo.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: 57c6b47e-257b-485e-a1f6-e343d18c623e X-Archives-Hash: eae111d471d31d14f3914c56f6623094 Signed-off-by: Michał Górny --- 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: +# @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 -- 2.43.0