diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-04-25 19:13:54 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-04-25 19:13:54 -0400 |
commit | 474fabf287cca3c65175bf05a75ae850326d9c36 (patch) | |
tree | 9a77102ba80089283cc30fc8bc763b4c5e33145e /lib/common.sh | |
parent | ea39ed2b8f3aeafcb6ec8650af0aa703f41925e8 (diff) |
lib/common.sh: Make setup_workdir()/cleanup() safe for programs to not use
Diffstat (limited to 'lib/common.sh')
-rw-r--r-- | lib/common.sh | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/common.sh b/lib/common.sh index 932799e..d6fbe7c 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -57,13 +57,19 @@ 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" - [[ $1 ]] && exit $1 + if [[ -n $WORKDIR ]] && $_setup_workdir; then + rm -rf "$WORKDIR" + fi + [[ -n $1 ]] && exit $1 } abort() { @@ -86,9 +92,6 @@ die() { cleanup 1 } -trap 'trap_abort' INT QUIT TERM HUP -trap 'trap_exit' EXIT - ## # usage : in_array( $needle, $haystack ) # return : 0 - found |