Skip to content

Commit 9d026c9

Browse files
fix(scripts): use sentinel file to detect per-attempt .rej files
patch --forward creates .rej files for reversed/already-applied hunks even when it exits non-zero. Using -newer patch_path was unreliable because the cached patch file is old. Use a mktemp sentinel created immediately before each patch attempt so only rejects from that specific attempt are detected. Also clean up .rej files on skip to avoid false positives in subsequent patches.
1 parent af31ddb commit 9d026c9

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

scripts/apply-patches.sh

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,35 @@ apply_series() {
6565
continue
6666
fi
6767

68-
# --forward skips hunks already present in the tree (exit 0).
69-
# If the patch encodes a stable-point-release version (e.g. v6.19.10-lqx2.patch)
70-
# that the tree already satisfies, skip it rather than failing.
68+
# If the patch filename encodes a stable-point-release version
69+
# (e.g. v6.19.10-lqx2.patch) that the tree already satisfies,
70+
# skip it unconditionally — applying it would produce mass rejects.
7171
local patch_name
7272
patch_name=$(basename "${patch_path}")
73-
local patch_kver=""
7473
if [[ "${patch_name}" =~ ^v([0-9]+\.[0-9]+\.[0-9]+)- ]]; then
75-
patch_kver="${BASH_REMATCH[1]}"
76-
fi
77-
78-
if [[ -n "${patch_kver}" ]]; then
74+
local patch_kver="${BASH_REMATCH[1]}"
7975
local tree_kver
80-
tree_kver=$(make -s -C "${KERNEL_SRC}" kernelversion 2>/dev/null | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
81-
if [[ "${patch_kver}" == "${tree_kver}" ]]; then
76+
tree_kver=$(make -s -C "${KERNEL_SRC}" kernelversion 2>/dev/null \
77+
| grep -oE '^[0-9]+\.[0-9]+\.[0-9]+' || true)
78+
if [[ -n "${tree_kver}" && "${patch_kver}" == "${tree_kver}" ]]; then
8279
log WARN "patch targets ${patch_kver} which matches tree version — skipping: ${line}"
8380
(( skipped++ )) || true
8481
continue
8582
fi
8683
fi
8784

85+
# Use a sentinel file to detect .rej files created by this specific attempt
86+
local sentinel
87+
sentinel=$(mktemp "${KERNEL_SRC}/.lqxm_sentinel_XXXXXX")
88+
8889
if ! patch -p1 --forward -d "${KERNEL_SRC}" < "${patch_path}" 2>/dev/null; then
89-
# Check whether any .rej files were created (genuine conflict)
90-
if find "${KERNEL_SRC}" -name '*.rej' -newer "${patch_path}" | grep -q .; then
90+
# Check for .rej files newer than our sentinel (genuine conflict)
91+
local new_rejects
92+
new_rejects=$(find "${KERNEL_SRC}" -name '*.rej' -newer "${sentinel}" 2>/dev/null)
93+
rm -f "${sentinel}"
94+
if [[ -n "${new_rejects}" ]]; then
95+
# Clean up rejects before reporting so the tree is left tidy
96+
echo "${new_rejects}" | xargs rm -f
9197
log ERROR "patch failed with rejects: ${line}"
9298
log ERROR "Resolve conflicts in ${KERNEL_SRC}, then re-run with --no-fetch."
9399
exit 1
@@ -96,6 +102,7 @@ apply_series() {
96102
(( skipped++ )) || true
97103
continue
98104
fi
105+
rm -f "${sentinel}"
99106
(( applied++ )) || true
100107
done < "${series_file}"
101108

0 commit comments

Comments
 (0)