From 71afd4d88f2d63a8d70f3424bc2c2c1a8e766a85 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Wed, 27 Nov 2024 19:46:48 +1000 Subject: [PATCH] libmakepkg - add wrapper function for objcopy Using objcopy can result in file permission changes. We work around this by using "cat" to copy the temporary output file into the target. Extract this code into a utility function. Signed-off-by: Allan McRae --- scripts/libmakepkg/tidy/strip.sh.in | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in index 2ab68479..cf814323 100644 --- a/scripts/libmakepkg/tidy/strip.sh.in +++ b/scripts/libmakepkg/tidy/strip.sh.in @@ -66,6 +66,14 @@ package_source_files() { done < <(source_files "$binary") } +safe_objcopy() { + local binary=$1; shift + local tempfile=$(mktemp "$binary.XXXXXX") + objcopy "$@" "$binary" "$tempfile" + cat "$tempfile" > "$binary" + rm "$tempfile" +} + collect_debug_symbols() { local binary=$1; shift @@ -92,10 +100,7 @@ collect_debug_symbols() { return fi - local tempfile=$(mktemp "$binary.XXXXXX") - objcopy --add-gnu-debuglink="$dbgdir/${binary#/}.debug" "$binary" "$tempfile" - cat "$tempfile" > "$binary" - rm "$tempfile" + safe_objcopy "$binary" --add-gnu-debuglink="$dbgdir/${binary#/}.debug" # create any needed hardlinks while IFS= read -rd '' file ; do