Skip to content

Commit 93c0a18

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 93c0a18

2 files changed

Lines changed: 53 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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
#
3+
# Shared helper functions for kpatch-build (and tests).
4+
#
5+
# Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
6+
# Copyright (C) 2013,2014 Josh Poimboeuf <jpoimboe@redhat.com>
7+
#
8+
# This program is free software; you can redistribute it and/or
9+
# modify it under the terms of the GNU General Public License
10+
# as published by the Free Software Foundation; either version 2
11+
# of the License, or (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program; if not, write to the Free Software
20+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA,
21+
# 02110-1301, USA.
22+
23+
# Find and move the linux source directory from an RPM BUILD tree.
24+
# Handles both traditional flat layout (Fedora < 42, RHEL, CentOS):
25+
# BUILD/kernel-6.12.0/linux-6.12.0-100.fc41.x86_64/
26+
# and nested layout (Fedora 42+):
27+
# BUILD/kernel-6.14.0-build/kernel-6.14/linux-6.14.0-63.fc42.x86_64/
28+
#
29+
# Uses: RPMTOPDIR, KERNEL_SRCDIR (must be set by caller)
30+
find_rpm_linux_srcdir() {
31+
shopt -s nullglob
32+
local dirs=( "$RPMTOPDIR"/BUILD/kernel-*/linux-* )
33+
shopt -u nullglob
34+
35+
if [[ ${#dirs[@]} -eq 1 ]]; then
36+
mv "${dirs[0]}" "$KERNEL_SRCDIR" 2>&1 | logger || die
37+
elif [[ ${#dirs[@]} -gt 1 ]]; then
38+
die "Multiple linux-* directories found in BUILD: ${dirs[*]}"
39+
else
40+
local found
41+
found=$(find "$RPMTOPDIR/BUILD" -maxdepth 3 -type d -name "linux-*" \
42+
! -path "*/configs/*")
43+
if [[ -z "$found" ]]; then
44+
die "Could not find linux source directory under $RPMTOPDIR/BUILD"
45+
elif [[ $(echo "$found" | wc -l) -gt 1 ]]; then
46+
die "Multiple linux source directories under $RPMTOPDIR/BUILD: $found"
47+
else
48+
mv "$found" "$KERNEL_SRCDIR" 2>&1 | logger || die
49+
fi
50+
fi
51+
}

0 commit comments

Comments
 (0)