Skip to content

Commit 96c5ebd

Browse files
oshovalcursoragent
andcommitted
kpatch-build: fix Fedora 42+ kernel source directory nesting
Starting with Fedora 42, the kernel SRPM unpacks with an extra level of nesting: BUILD/kernel-6.14.0-build/kernel-6.14/linux-6.14.0-63.fc42.x86_64/ The existing glob BUILD/kernel-*/linux-* only matches the traditional flat layout and fails on this structure. Extract the source-finding logic into find_rpm_linux_srcdir() in a new kpatch-funcs.sh, using nullglob with a bash array to safely count flat-glob matches: - Exactly one match: move it (traditional RHEL/CentOS/Fedora < 42). - Multiple matches: die with a clear diagnostic. - Zero matches: search deeper with find -maxdepth 3, excluding configs/ directories, again requiring exactly one result. Signed-off-by: Or Shoval <oshoval@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 7552b46 commit 96c5ebd

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

kpatch-build/kpatch-build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set -o pipefail
3939

4040
BASE="$PWD"
4141
SCRIPTDIR="$(readlink -f "$(dirname "$(type -p "$0")")")"
42+
source "$SCRIPTDIR/kpatch-funcs.sh"
4243
ARCH="$(uname -m)"
4344
TARGET_ARCH="${TARGET_ARCH:-$ARCH}"
4445
CPUS="$(getconf _NPROCESSORS_ONLN)"
@@ -1082,7 +1083,7 @@ else
10821083
elif [[ "$DISTRO" = photon ]]; then
10831084
mv "$RPMTOPDIR"/BUILD/linux-"$KVER" "$KERNEL_SRCDIR" 2>&1 | logger || die
10841085
else
1085-
mv "$RPMTOPDIR"/BUILD/kernel-*/linux-* "$KERNEL_SRCDIR" 2>&1 | logger || die
1086+
find_rpm_linux_srcdir
10861087
fi
10871088

10881089
rm -rf "$RPMTOPDIR"

kpatch-build/kpatch-funcs.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
# Shared helper functions for kpatch-build (and tests).
3+
4+
# Find and move the linux source directory from an RPM BUILD tree.
5+
# Handles both traditional flat layout (Fedora < 42, RHEL, CentOS):
6+
# BUILD/kernel-6.12.0/linux-6.12.0-100.fc41.x86_64/
7+
# and nested layout (Fedora 42+):
8+
# BUILD/kernel-6.14.0-build/kernel-6.14/linux-6.14.0-63.fc42.x86_64/
9+
#
10+
# Uses: RPMTOPDIR, KERNEL_SRCDIR (must be set by caller)
11+
find_rpm_linux_srcdir() {
12+
shopt -s nullglob
13+
local dirs=( "$RPMTOPDIR"/BUILD/kernel-*/linux-* )
14+
shopt -u nullglob
15+
16+
if [[ ${#dirs[@]} -eq 1 ]]; then
17+
mv "${dirs[0]}" "$KERNEL_SRCDIR" 2>&1 | logger || die
18+
elif [[ ${#dirs[@]} -gt 1 ]]; then
19+
die "Multiple linux-* directories found in BUILD: ${dirs[*]}"
20+
else
21+
local found count
22+
found=$(find "$RPMTOPDIR/BUILD" -maxdepth 3 -type d -name "linux-*" \
23+
! -path "*/configs/*")
24+
count=$(echo "$found" | grep -c . || true)
25+
if [[ "$count" -eq 1 ]]; then
26+
mv "$found" "$KERNEL_SRCDIR" 2>&1 | logger || die
27+
elif [[ "$count" -gt 1 ]]; then
28+
die "Multiple linux source directories under $RPMTOPDIR/BUILD: $found"
29+
else
30+
die "Could not find linux source directory under $RPMTOPDIR/BUILD"
31+
fi
32+
fi
33+
}

0 commit comments

Comments
 (0)