Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@parabola.nu>2013-04-25 19:13:54 -0400
committerLuke Shumaker <lukeshu@parabola.nu>2017-02-06 03:14:35 -0500
commitbdd7c46322a93d4a98202e574f8e65fcd379e5ef (patch)
tree0dc02b684ccc5e87722ae50a9038b2c3ee621b68
parent997d54d425c69fd1f816340eab46a0b72338cc15 (diff)
lib/common.sh: Make setup_workdir()/cleanup() safe for programs to not use
-rw-r--r--lib/common.sh11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/common.sh b/lib/common.sh
index d2a244f..dbacebf 100644
--- a/lib/common.sh
+++ b/lib/common.sh
@@ -59,12 +59,18 @@ stat_done() {
printf "${BOLD}done${ALL_OFF}\n" >&2
}
+_setup_workdir=false
setup_workdir() {
[[ -z $WORKDIR ]] && WORKDIR=$(mktemp -d --tmpdir "${0##*/}.XXXXXXXXXX")
+ _setup_workdir=true
+ trap 'trap_abort' INT QUIT TERM HUP
+ trap 'trap_exit' EXIT
}
cleanup() {
- [[ -n $WORKDIR ]] && rm -rf "$WORKDIR"
+ if [[ -n $WORKDIR ]] && $_setup_workdir; then
+ rm -rf "$WORKDIR"
+ fi
exit ${1:-0}
}
@@ -89,9 +95,6 @@ die() {
cleanup 255
}
-trap 'trap_abort' INT QUIT TERM HUP
-trap 'trap_exit' EXIT
-
##
# usage : in_array( $needle, $haystack )
# return : 0 - found