public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/3] dist-kernel-utils.eclass: Add dist-kernel_compressed_module_cleanup
@ 2023-12-28 12:21 Michał Górny
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Michał Górny @ 2023-12-28 12:21 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-28 12:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-28 12:21 [gentoo-dev] [PATCH 1/3] dist-kernel-utils.eclass: Add dist-kernel_compressed_module_cleanup Michał Górny
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox