Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

livepatch/klp-build: support patches that add/remove files

The klp-build script prepares a clean patch by populating two temporary
directories ('a' and 'b') with source files and diffing the result.
However, this process fails when a patch introduces a new source file,
as the script attempts to copy files that do not yet exist in the
original source tree. Likewise, it fails when a patch removes a source
file and the script attempts to copy a file that no longer exists.

Refactor the file-gathering logic to distinguish between original input
files and patched output files:

- Split get_patch_files() into get_patch_input_files() and
get_patch_output_files() to identify which files exist before and
after patch application.
- Filter out "/dev/null" from both to handle file creation/deletion.
- Update refresh_patch() to only copy existing input files to the 'a'
directory and the resulting output files to the 'b' directory.

Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Link: https://patch.msgid.link/20260310203751.1479229-4-joe.lawrence@redhat.com
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

authored by

Joe Lawrence and committed by
Josh Poimboeuf
757bd10f 4b57e97b

+28 -8
+28 -8
scripts/livepatch/klp-build
··· 296 296 sed -i "2i echo $localversion; exit 0" scripts/setlocalversion 297 297 } 298 298 299 + get_patch_input_files() { 300 + local patch="$1" 301 + 302 + grep0 -E '^--- ' "$patch" \ 303 + | gawk '{print $2}' \ 304 + | grep0 -v '^/dev/null$' \ 305 + | sed 's|^[^/]*/||' \ 306 + | sort -u 307 + } 308 + 309 + get_patch_output_files() { 310 + local patch="$1" 311 + 312 + grep0 -E '^\+\+\+ ' "$patch" \ 313 + | gawk '{print $2}' \ 314 + | grep0 -v '^/dev/null$' \ 315 + | sed 's|^[^/]*/||' \ 316 + | sort -u 317 + } 318 + 299 319 get_patch_files() { 300 320 local patch="$1" 301 321 302 - grep0 -E '^(--- |\+\+\+ )' "$patch" \ 303 - | gawk '{print $2}' \ 304 - | sed 's|^[^/]*/||' \ 322 + { get_patch_input_files "$patch"; get_patch_output_files "$patch"; } \ 305 323 | sort -u 306 324 } 307 325 ··· 330 312 331 313 [[ ! -e "$SRC/.git" ]] && return 332 314 333 - get_patch_files "$patch" | mapfile -t files 315 + get_patch_input_files "$patch" | mapfile -t files 334 316 335 317 ( 336 318 cd "$SRC" ··· 444 426 refresh_patch() { 445 427 local patch="$1" 446 428 local tmpdir="$PATCH_TMP_DIR" 447 - local files=() 429 + local input_files=() 430 + local output_files=() 448 431 449 432 rm -rf "$tmpdir" 450 433 mkdir -p "$tmpdir/a" 451 434 mkdir -p "$tmpdir/b" 452 435 453 436 # Get all source files affected by the patch 454 - get_patch_files "$patch" | mapfile -t files 437 + get_patch_input_files "$patch" | mapfile -t input_files 438 + get_patch_output_files "$patch" | mapfile -t output_files 455 439 456 440 # Copy orig source files to 'a' 457 - ( cd "$SRC" && echo "${files[@]}" | xargs cp --parents --target-directory="$tmpdir/a" ) 441 + ( cd "$SRC" && echo "${input_files[@]}" | xargs cp --parents --target-directory="$tmpdir/a" ) 458 442 459 443 # Copy patched source files to 'b' 460 444 apply_patch "$patch" --recount 461 - ( cd "$SRC" && echo "${files[@]}" | xargs cp --parents --target-directory="$tmpdir/b" ) 445 + ( cd "$SRC" && echo "${output_files[@]}" | xargs cp --parents --target-directory="$tmpdir/b" ) 462 446 revert_patch "$patch" --recount 463 447 464 448 # Diff 'a' and 'b' to make a clean patch