commit:     40e35a1b2001aae0741c54595c2ea871274c37be
Author:     Georgy Yakovlev <gyakovlev <AT> gentoo <DOT> org>
AuthorDate: Thu Dec  1 23:50:38 2022 +0000
Commit:     Georgy Yakovlev <gyakovlev <AT> gentoo <DOT> org>
CommitDate: Sat Dec  3 21:59:26 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=40e35a1b

sys-fs/zfs-kmod: clean up old modules in live ebuild

Signed-off-by: Georgy Yakovlev <gyakovlev <AT> gentoo.org>

 sys-fs/zfs-kmod/zfs-kmod-9999.ebuild | 37 ++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/sys-fs/zfs-kmod/zfs-kmod-9999.ebuild 
b/sys-fs/zfs-kmod/zfs-kmod-9999.ebuild
index b2fa04c9966a..3e4508af22fc 100644
--- a/sys-fs/zfs-kmod/zfs-kmod-9999.ebuild
+++ b/sys-fs/zfs-kmod/zfs-kmod-9999.ebuild
@@ -174,7 +174,44 @@ src_install() {
        einstalldocs
 }
 
+_old_layout_cleanup() {
+       # new files are just extra/{spl,zfs}.ko with no subdirs.
+       local olddir=(
+               avl/zavl
+               icp/icp
+               lua/zlua
+               nvpair/znvpair
+               spl/spl
+               unicode/zunicode
+               zcommon/zcommon
+               zfs/zfs
+               zstd/zzstd
+       )
+
+       # kernel/module/Kconfig contains possible compressed extentions.
+       local kext kextfiles
+       for kext in .ko{,.{gz,xz,zst}}; do
+               kextfiles+=( "${olddir[@]/%/${kext}}" )
+       done
+
+       local oldfile oldpath
+       for oldfile in "${kextfiles[@]}"; do
+               oldpath="${EROOT}/lib/modules/${KV_FULL}/extra/${oldfile}"
+               if [[ -f "${oldpath}" ]]; then
+                       ewarn "Found obsolete zfs module ${oldfile} for current 
kernel ${KV_FULL}, removing."
+                       rm -rv "${oldpath}" || die
+                       # we do not remove non-empty directories just for 
safety in case there's something else.
+                       # also it may fail if there are both compressed and 
uncompressed modules installed.
+                       rmdir -v --ignore-fail-on-non-empty "${oldpath%/*.*}" 
|| die
+               fi
+       done
+}
+
 pkg_postinst() {
+       # check for old module layout before doing anything else.
+       # only attempt layout cleanup if new .ko location is used.
+       [[ -f "${EROOT}/lib/modules/${KV_FULL}/extra/zfs.ko" ]] && 
_old_layout_cleanup
+
        linux-mod_pkg_postinst
 
        if [[ -z ${ROOT} ]] && use dist-kernel; then

Reply via email to