aboutsummaryrefslogtreecommitdiff
path: root/lib/hydra/tmpfile
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2010-09-25 23:37:23 -0300
committerSilvio Rhatto <rhatto@riseup.net>2010-09-25 23:37:23 -0300
commit3346311096bee29b81190ceb377ef5648aee1380 (patch)
tree84f99fb82853416b2e2cd1c3b0f09ae86eff1d8d /lib/hydra/tmpfile
parentc36794e899731be16f1045a9ae19878813fd9896 (diff)
downloadhydra-3346311096bee29b81190ceb377ef5648aee1380.tar.gz
hydra-3346311096bee29b81190ceb377ef5648aee1380.tar.bz2
New/renamed actions
Diffstat (limited to 'lib/hydra/tmpfile')
-rw-r--r--lib/hydra/tmpfile45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/hydra/tmpfile b/lib/hydra/tmpfile
new file mode 100644
index 0000000..886d61c
--- /dev/null
+++ b/lib/hydra/tmpfile
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# Setup a temporary file
+function hydra_set_tmpfile {
+ if [ -z "$BASEDIR" ]; then
+ echo "Please set BASEDIR before creating a tmp file"
+ exit 1
+ fi
+
+ if [ -z "$1" ]; then
+ template="$BASEDIR/tmp/hydra.XXXXXXXXXX"
+ else
+ template="$BASEDIR/tmp/$1.XXXXXXXXXX"
+ fi
+
+ mkdir -p $BASEDIR/tmp
+ hydra_git_ignore 'tmp/*'
+
+ if [ "$2" == "-d" ]; then
+ TMPWORK="`mktemp -d $template`"
+ else
+ TMPWORK="`mktemp $template`"
+ fi
+
+ if [ "$?" != "0" ]; then
+ echo "Error: can't set TMPWORK $TMPWORK"
+ exit 1
+ fi
+
+ trap "hydra_unset_tmpfile $TMPWORK; exit" INT TERM EXIT
+}
+
+# Remove a temporary file
+function hydra_unset_tmpfile {
+ if [ -z "$1" ]; then
+ echo "No tmp file set"
+ fi
+
+ rm -f $1
+
+ if [ "$?" != "0" ]; then
+ echo "Warning: could not delete file $1. Please delete it manually as it might have sensitive information."
+ exit 1
+ fi
+}