Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 947359 - kernel-install.eclass: kernel-install_pkg_postrm: find: No such file or directory
Summary: kernel-install.eclass: kernel-install_pkg_postrm: find: No such file or direc...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Distribution Kernel Project
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-01-02 13:55 UTC by Fab
Modified: 2025-01-06 14:37 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
kernel unmerge (kernel-unmerge.log,978 bytes, text/plain)
2025-01-02 13:56 UTC, Fab
Details
remove empty directory if it exists (fix.patch,445 bytes, text/plain)
2025-01-05 08:08 UTC, Fab
Details
remove empty directory only if it exists (fix.patch,476 bytes, patch)
2025-01-05 09:56 UTC, Fab
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fab 2025-01-02 13:55:40 UTC
Hi,

I'm using sys-kernel/gentoo-kernel-bin with useflag initramfs disabled.
I do not have any initramfs.

Each time I unmerge a kernel version I'm getting an error from find.
The error comes from kernel-install_pkg_postrm() defined in kernel-install.eclass.

See the following attached file.

Reproducible: Always
Comment 1 Fab 2025-01-02 13:56:31 UTC
Created attachment 915741 [details]
kernel unmerge
Comment 2 Fab 2025-01-05 08:08:27 UTC
Created attachment 915864 [details]
remove empty directory if it exists

This patch is fixing the issue for me :

> Would you like to unmerge these packages? [Yes/No] yes
> >>> Waiting 5 seconds before starting...
> >>> (Control-C to abort)...
> >>> Unmerging in: 5 4 3 2 1
> >>> Unmerging (1 of 1) sys-kernel/gentoo-kernel-bin-5.15.175...
>  * Removing initramfs ...               [ ok ]
> 
> * GNU info directory index is up-to-date.
Comment 3 Fab 2025-01-05 09:56:32 UTC
Created attachment 915894 [details, diff]
remove empty directory only if it exists

Second version of the patch to properly consider the rmdir return value.
Comment 4 Nowa Ammerlaan gentoo-dev 2025-01-06 08:46:12 UTC
(In reply to Fab from comment #3)
> Created attachment 915894 [details, diff] [details, diff]
> remove empty directory only if it exists
> 
> Second version of the patch to properly consider the rmdir return value.

This fix modifies the intended behaviour. The find strips empty directories only, whereas after this patch the whole kernel source tree would be removed which is not what we want.

I propose this fix instead, could you let me know if it resolves the problem on your end?

diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index 6ca39e551110..f70556ad41f5 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -738,9 +738,9 @@ kernel-install_pkg_postinst() {
 kernel-install_pkg_postrm() {
 	debug-print-function ${FUNCNAME} "$@"
 
-	if [[ ! ${KERNEL_IUSE_GENERIC_UKI} ]]; then
-		local kernel_dir=${EROOT}/usr/src/linux-${KV_FULL}
-		local image_path=$(dist-kernel_get_image_path)
+	local kernel_dir=${EROOT}/usr/src/linux-${KV_FULL}
+	local image_path=$(dist-kernel_get_image_path)
+	if [[ ! ${KERNEL_IUSE_GENERIC_UKI} && -d ${kernel_dir} ]]; then
 		ebegin "Removing initramfs"
 		rm -f "${kernel_dir}/${image_path%/*}"/{initrd,uki.efi} &&
 			find "${kernel_dir}" -depth -type d -empty -delete
Comment 5 Fab 2025-01-06 09:15:29 UTC
Yes, this works fine. Thank you.
Comment 6 Larry the Git Cow gentoo-dev 2025-01-06 14:37:54 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=65594d38630d5406918d60ebd6d2aba7367aad6b

commit 65594d38630d5406918d60ebd6d2aba7367aad6b
Author:     Nowa Ammerlaan <nowa@gentoo.org>
AuthorDate: 2025-01-06 09:20:31 +0000
Commit:     Nowa Ammerlaan <nowa@gentoo.org>
CommitDate: 2025-01-06 14:37:49 +0000

    kernel-install.eclass: only remove initrd,uki.efi if src dir still exists
    
    Closes: https://bugs.gentoo.org/947359
    Signed-off-by: Nowa Ammerlaan <nowa@gentoo.org>

 eclass/kernel-install.eclass | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)