summaryrefslogtreecommitdiff
path: root/lib/common.sh
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@parabola.nu>2017-03-25 12:34:41 -0400
committerJan Alexander Steffens (heftig) <jan.steffens@gmail.com>2017-04-05 22:03:00 +0200
commit8ff247de13ef9b9ff311f6eff46ba3a871984fae (patch)
tree120ae499eba76e5f645760bcf355504ec39db435 /lib/common.sh
parentd4f09b2c7b36c78500bec769c98ebc04c0a19e7d (diff)
downloaddevtools-8ff247de13ef9b9ff311f6eff46ba3a871984fae.tar.xz
lib/common.sh: Make setup_workdir()/cleanup() safe for programs to not use
Diffstat (limited to 'lib/common.sh')
-rw-r--r--lib/common.sh11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/common.sh b/lib/common.sh
index 6d873ed..5ef9f97 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