From 828b557b50aae78e584670ef6c35356c10da56cd Mon Sep 17 00:00:00 2001 From: Julian Stecklina Date: Fri, 12 Jul 2024 09:35:02 +0200 Subject: [PATCH] Fix cleanup when kpatch is installed in read-only location On NixOS files are installed with mode 444 (read-only). This causes directories in $TEMPDIR to be read-only as well, because they are created by: cp -LR "$DATADIR/patch" "$TEMPDIR" || die which preserves the mode of the directory. We could do --no-preserve=mode, but this will make people with non-coreutils cp unhappy. Instead just chmod the files after copying. If this patch is not applied, cleanup complains like this: rm: cannot remove '/home/julian/.kpatch/tmp/patch/kpatch.h': Permission denied rm: cannot remove '/home/julian/.kpatch/tmp/patch/Makefile': Permission denied rm: cannot remove '/home/julian/.kpatch/tmp/patch/kpatch-macros.h': Permission denied ... Signed-off-by: Julian Stecklina --- kpatch-build/kpatch-build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index 366adea..215c823 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -1236,7 +1236,10 @@ verify_patch_files apply_patches remove_patches +# cp preserves mode and the files might have been read-only. This would +# interfere with cleanup later, so ensure the $TEMPDIR is read/write. cp -LR "$DATADIR/patch" "$TEMPDIR" || die +chmod -R u+rw "$TEMPDIR" || die if [[ "$ARCH" = "ppc64le" ]]; then ARCH_KCFLAGS="-mcmodel=large -fplugin=$PLUGINDIR/ppc64le-plugin.so"