tmpdir.sh: Use the -t flag for mktemp

This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-06-11 17:07:38 -03:00
parent 8932011e7c
commit 07081d5761
2 changed files with 26 additions and 2 deletions

View File

@@ -45,7 +45,8 @@ mk_tmpdir() {
else
local tool="${0##*/}"
local pid="$$"
TMPDIR=`mktemp -d /tmp/${tool}.${pid}.XXXXXX` \
local x="$TMPDIR"
TMPDIR=`TMPDIR="$x" mktemp -d -t "${tool}.${pid}.XXXXXX"` \
|| die "Cannot make secure tmpdir"
fi
}

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
plan 9
plan 10
source "$LIB_DIR/log_warn_die.sh"
source "$LIB_DIR/tmpdir.sh"
@@ -36,6 +36,29 @@ rm_tmpdir
cmd_ok "test ! -d $tmpdir" "rm_tmpdir removes --tmpdir"
# ###########################################################################
# Bug 945079: tmpdir should respect $TEMP
# ###########################################################################
tempdir_test () {
new_TEMP="/tmp/tmpdir_test"
rm -rf "$new_TEMP"
mkdir "$new_TEMP"
local TMPDIR="$new_TEMP/"
mk_tmpdir
is "$(dirname "$TMPDIR")" \
"$new_TEMP" \
'mk_tmpdir respects $TMPDIR'
rm_tmpdir
rm -rf "$new_TEMP"
}
tempdir_test
# ###########################################################################
# Done
# ###########################################################################