Skip to content

Commit 5bd7160

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 one level deep and fails on this layout. Use 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 one level deeper with find -maxdepth 3, again requiring exactly one result before proceeding. All mv calls preserve the original "2>&1 | logger || die" error handling, and ambiguous matches are always fatal. Tested on Fedora 42 with kernel 6.14.0-63.fc42.x86_64. Signed-off-by: Or Shoval <oshoval@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 7552b46 commit 5bd7160

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

kpatch-build/kpatch-build

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,28 @@ else
10821082
elif [[ "$DISTRO" = photon ]]; then
10831083
mv "$RPMTOPDIR"/BUILD/linux-"$KVER" "$KERNEL_SRCDIR" 2>&1 | logger || die
10841084
else
1085-
mv "$RPMTOPDIR"/BUILD/kernel-*/linux-* "$KERNEL_SRCDIR" 2>&1 | logger || die
1085+
# Fedora 42+ nests the source one level deeper:
1086+
# BUILD/kernel-X.Y.Z-build/kernel-X.Y/linux-X.Y.Z-NN.fcNN.ARCH/
1087+
# Check the traditional flat layout first; if not found, search deeper.
1088+
shopt -s nullglob
1089+
LINUX_DIRS=( "$RPMTOPDIR"/BUILD/kernel-*/linux-* )
1090+
shopt -u nullglob
1091+
if [[ ${#LINUX_DIRS[@]} -eq 1 ]]; then
1092+
mv "${LINUX_DIRS[0]}" "$KERNEL_SRCDIR" 2>&1 | logger || die
1093+
elif [[ ${#LINUX_DIRS[@]} -gt 1 ]]; then
1094+
die "Multiple linux-* directories found in BUILD: ${LINUX_DIRS[*]}"
1095+
else
1096+
LINUX_SRC=$(find "$RPMTOPDIR/BUILD" -maxdepth 3 -type d -name "linux-*" \
1097+
! -path "*/configs/*")
1098+
MATCH_COUNT=$(echo "$LINUX_SRC" | grep -c . || true)
1099+
if [[ "$MATCH_COUNT" -eq 1 ]]; then
1100+
mv "$LINUX_SRC" "$KERNEL_SRCDIR" 2>&1 | logger || die
1101+
elif [[ "$MATCH_COUNT" -gt 1 ]]; then
1102+
die "Multiple linux source directories under $RPMTOPDIR/BUILD: $LINUX_SRC"
1103+
else
1104+
die "Could not find linux source directory under $RPMTOPDIR/BUILD"
1105+
fi
1106+
fi
10861107
fi
10871108

10881109
rm -rf "$RPMTOPDIR"

0 commit comments

Comments
 (0)