Merge pull request #179896 from erikarvstedt/fix-bash-exit-handler

treewide: fix bash exit handlers
This commit is contained in:
Sebastián Mancilla 2022-08-14 21:42:41 -04:00 committed by GitHub
commit 10a745eac8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 19 deletions

View file

@ -35,7 +35,7 @@ toRemove=()
cleanup() {
rm -rf "${toRemove[@]}"
}
trap cleanup EXIT SIGINT SIGQUIT ERR
trap cleanup EXIT
MKTEMP='mktemp --tmpdir nix-rebuild-amount-XXXXXXXX'

View file

@ -23,12 +23,10 @@ let
on_exit()
{
exitStatus=$?
# Reset the EXIT handler, or else we're called again on 'exit' below
trap - EXIT
${cfg.postHook}
exit $exitStatus
}
trap 'on_exit' INT TERM QUIT EXIT
trap on_exit EXIT
archiveName="${if cfg.archiveBaseName == null then "" else cfg.archiveBaseName + "-"}$(date ${cfg.dateFormat})"
archiveSuffix="${optionalString cfg.appendFailedSuffix ".failed"}"

View file

@ -562,7 +562,7 @@ in
shopt -s inherit_errexit
create_role="$(mktemp)"
trap 'rm -f "$create_role"' ERR EXIT
trap 'rm -f "$create_role"' EXIT
db_password="$(<"$CREDENTIALS_DIRECTORY/db_password")"
echo "CREATE ROLE keycloak WITH LOGIN PASSWORD '$db_password' CREATEDB" > "$create_role"

View file

@ -37,14 +37,12 @@ prefetchExtensionUnpacked() {
1>&2 echo "zipStorePath='$zipStorePath'"
function rm_tmpdir() {
1>&2 printf "rm -rf -- %q\n" "$tmpDir"
rm -rf -- "$tmpDir"
unset tmpDir
trap - INT TERM HUP EXIT
1>&2 printf "rm -rf %q\n" "$tmpDir"
rm -rf "$tmpDir"
}
function make_trapped_tmpdir() {
tmpDir=$(mktemp -d)
trap rm_tmpdir INT TERM HUP EXIT
trap rm_tmpdir EXIT
}
1>&2 echo

View file

@ -44,14 +44,11 @@ extStoreName="${extPublisher}-${extName}"
function rm_tmpdir() {
#echo "Removing \`tmpDir='$tmpDir'\`"
rm -rf -- "$tmpDir"
unset tmpDir
trap - INT TERM HUP EXIT
rm -rf "$tmpDir"
}
function make_trapped_tmpdir() {
tmpDir=$(mktemp -d)
trap rm_tmpdir INT TERM HUP EXIT
trap rm_tmpdir EXIT
}
echo

View file

@ -21,13 +21,11 @@ fi
mkTempDir() {
tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/nix-prefetch-cvs-XXXXXXXX")"
trap removeTempDir EXIT SIGINT SIGQUIT
trap removeTempDir EXIT
}
removeTempDir() {
if test -n "$tmpPath"; then
rm -rf "$tmpPath" || true
fi
rm -rf "$tmpPath"
}