[pacman-dev] [PATCH] updpkgsums: retain permissions on rewritten PKGBUILD
This could have been easy with something like chown's --reference flag, but this is GNU specific. Instead, just truncate and rewrite the file. Our exit trap cleans up after us. Fixes: https://bugs.archlinux.org/task/43272 --- contrib/updpkgsums.sh.in | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/contrib/updpkgsums.sh.in b/contrib/updpkgsums.sh.in index b0d2d69..7b92efe 100644 --- a/contrib/updpkgsums.sh.in +++ b/contrib/updpkgsums.sh.in @@ -82,9 +82,6 @@ fi export BUILDDIR=$(mktemp -d --tmpdir updpkgsums.XXXXXX) newbuildfile=$(mktemp --tmpdir updpkgsums.XXXXXX) -# In case the eventual replacement fails, we don't want to leave behind -# $newbuildfile as garbage in $TMPDIR. This fails silently if the replacement -# succeeds. trap "rm -rf '$BUILDDIR' '$newbuildfile'" EXIT newsums=$(makepkg -g -p "$buildfile") || die 'Failed to generate new checksums' awk -v newsums="$newsums" ' @@ -100,8 +97,9 @@ awk -v newsums="$newsums" ' END { if (!w) print newsums } ' "$buildfile" > "$newbuildfile" || die 'Failed to write new PKGBUILD' -# Replace the original buildfile. -if ! mv -- "$newbuildfile" "$buildfile"; then +# Rewrite the original buildfile. Use cat instead of mv/cp to preserve +# permissions implicitly. +if ! cat -- "$newbuildfile" >"$buildfile"; then die "Failed to update %s. The file has not been modified." "$buildfile" fi -- 2.2.1
participants (1)
-
Dave Reisner