From ca5a2771aeb0babca8270b83b0cb0172db4cebe5 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Wed, 31 Dec 2014 14:33:31 -0500 Subject: 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 Signed-off-by: Allan McRae --- contrib/updpkgsums.sh.in | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'contrib') diff --git a/contrib/updpkgsums.sh.in b/contrib/updpkgsums.sh.in index b0d2d69e..7b92efe3 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 -- cgit v1.2.3-70-g09d2