[pacman-dev] [PATCH] updpkgsums: Compute new checksum in temp directory
To avoid unwanted files to stay in the PKGBUILD directory after calling makepkg -g, we use a temporary build directory. This also prevent modifications of the current user work. Signed-off-by: Sébastien Luttringer <seblu@seblu.net> --- contrib/updpkgsums.sh.in | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/contrib/updpkgsums.sh.in b/contrib/updpkgsums.sh.in index ffea96b..401b8de 100644 --- a/contrib/updpkgsums.sh.in +++ b/contrib/updpkgsums.sh.in @@ -21,6 +21,7 @@ shopt -s extglob declare -r myname='updpkgsums' declare -r myver='@PACKAGE_VERSION@' +declare -i ret=0 usage() { printf 'usage: %s [buildfile]\n\n' "$myname" @@ -71,12 +72,26 @@ if [[ ! -w . ]]; then exit 1 fi +# Generate the new sums +# Use a temporary build directory to avoid unintented/unwanted side effects on +# the current user work. +# Ensure we clean the BUILDDIR before continue +export BUILDDIR=$(mktemp --directory $myname.XXXXX) +newsums=$(makepkg -g -p "$buildfile") +ret=$? +rm -r -f "$BUILDDIR" + +# Check we have generated new checksums before continue +if (( $ret != 0 )); then + echo '==> ERROR: Unable to generate new checksums' + exit 1 +fi + { - # Generate the new sums and try to unlink the file before writing stdin back - # into it. This final precaution shouldn't fail based on the previous checks, + # Unlink the file before writing stdin back into it. + # This final precaution shouldn't fail based on the previous checks, # but it's better to be extra careful before unlinking files. - newsums=$(makepkg -g -p "$buildfile") && rm -f "$buildfile" && - exec awk -v newsums="$newsums" ' + rm -f "$buildfile" && exec awk -v newsums="$newsums" ' /^[[:blank:]]*(md|sha)[[:digit:]]+sums=/,/\)[[:blank:]]*(#.*)?$/ { if (!w) { print newsums -- 1.8.2
On 07.04.2013 04:08, Sébastien Luttringer wrote:
To avoid unwanted files to stay in the PKGBUILD directory after calling makepkg -g, we use a temporary build directory.
This also prevent modifications of the current user work.
Signed-off-by: Sébastien Luttringer <seblu@seblu.net> --- contrib/updpkgsums.sh.in | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/contrib/updpkgsums.sh.in b/contrib/updpkgsums.sh.in index ffea96b..401b8de 100644 --- a/contrib/updpkgsums.sh.in +++ b/contrib/updpkgsums.sh.in [..] @@ -71,12 +72,26 @@ if [[ ! -w . ]]; then exit 1 fi
+# Generate the new sums +# Use a temporary build directory to avoid unintented/unwanted side effects on +# the current user work. +# Ensure we clean the BUILDDIR before continue +export BUILDDIR=$(mktemp --directory $myname.XXXXX) +newsums=$(makepkg -g -p "$buildfile") +ret=$? +rm -r -f "$BUILDDIR"
Please trap relevant signals here so this doesn't leave stale files if the user presses ^C.
participants (2)
-
Florian Pritz
-
Sébastien Luttringer