abuild: preserve attributes without setfattr/getfattr

The setfattr/getfattr commands were not guaranteed to be available and
abuild wouldn't properly error when they are not. That may cause some
hidden issues.

Changing the code to not need setfattr/getfattr like it is done in
default_dbg ([3ad93d9a83]) and pacman mkpkg ([pacman@88d054093c1]).

The code works by first writing the stripped output into a temporary file
and then replace the contents of the already existing file without changing
any file metadata.

[3ad93d9a83]: 3ad93d9a83
[pacman@88d054093c1]: 88d054093c
This commit is contained in:
Sertonix 2024-04-22 14:54:23 +02:00 committed by Natanael Copa
parent b3b42ae177
commit 06695133c9
2 changed files with 8 additions and 17 deletions

View File

@ -28,7 +28,6 @@ fi
: ${APK:="apk"}
: ${ADDUSER:="abuild-adduser"}
: ${ADDGROUP:="abuild-addgroup"}
: ${SETFATTR:="setfattr"}
apk_opt_wait="--wait 30"
doc_threshold=$((2 * 1024 * 1024)) # 2 MiB
@ -2600,6 +2599,8 @@ stripbin() {
esac
msg "Stripping binaries"
mkdir "$pkgbasedir/.strip-tmp"
scanelf --recursive --nobanner --osabi --etype "ET_DYN,ET_EXEC" . \
| while read type osabi filename; do
@ -2607,12 +2608,13 @@ stripbin() {
[ -e "$filename" ] || continue
[ "$osabi" != "STANDALONE" ] || continue
local XATTR=$(getfattr --match="" --dump "${filename}")
"${stripcmd}" "${filename}"
if [ -n "$XATTR" ]; then
echo "$XATTR" | "$SETFATTR" --restore=-
fi
local tmp="$pkgbasedir/.strip-tmp/${filename##*/}"
"${stripcmd}" -o "$tmp" "${filename}"
# only replace content to preserve attributes
cat "$tmp" > "$filename"
rm "$tmp"
done
rmdir "$pkgbasedir/.strip-tmp"
}
# simply list target apks

View File

@ -10,7 +10,6 @@ init_tests \
abuild_invalid_filename \
abuild_usr_lib64 \
abuild_dbg_subpackage \
abuild_SETFATTR_in_dbg \
abuild_reproducible \
abuild_checksum_generation \
abuild_checksum_duplicates \
@ -238,16 +237,6 @@ abuild_dbg_subpackage_body() {
fi
}
abuild_SETFATTR_in_dbg_body() {
init_keys
cp -ra "$testrepo"/dbgpkg .
cd dbgpkg
SETFATTR=true atf_check -s exit:0 \
-o match:"hello world" \
-e match:"Build complete" \
abuild
}
abuild_reproducible_body() {
init_keys
cp -ra "$testrepo" .