public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
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	[thread overview]
Message-ID: <20231228122106.1040252-1-mgorny@gentoo.org> (raw)

Signed-off-by: Michał Górny <mgorny@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
-- 
2.43.0



             reply	other threads:[~2023-12-28 12:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-28 12:21 Michał Górny [this message]
2023-12-28 12:21 ` [gentoo-dev] [PATCH 2/3] kernel-install.eclass: Call module cleanup in postinst Michał Górny
2023-12-28 12:21 ` [gentoo-dev] [PATCH 3/3] linux-mod-r1.eclass: " Michał Górny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231228122106.1040252-1-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox