refactor mktemp
This commit is contained in:
parent
c6061b377b
commit
b79045c6ee
31
urchin
31
urchin
|
@ -74,11 +74,28 @@ epoch_date() {
|
||||||
|
|
||||||
epoch_pax() {
|
epoch_pax() {
|
||||||
# Based on http://stackoverflow.com/a/7262588/407226
|
# Based on http://stackoverflow.com/a/7262588/407226
|
||||||
tmp="$(mktemp)"
|
tmp="$(mktemp_file)"
|
||||||
echo "ibase=8;$({ pax -wx cpio "${tmp}"; echo; } | cut -c 48-59)" | bc
|
echo "ibase=8;$({ pax -wx cpio "${tmp}"; echo; } | cut -c 48-59)" | bc
|
||||||
rm "${tmp}"
|
rm "${tmp}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mktemp_dir() {
|
||||||
|
# Support HP-UX mktemp that has wrong exit codes and
|
||||||
|
# can't make directories.
|
||||||
|
if test -f "${urchin_tmp}"; then
|
||||||
|
rm "${urchin_tmp}"
|
||||||
|
fi
|
||||||
|
mkdir "${urchin_tmp}"
|
||||||
|
}
|
||||||
|
|
||||||
|
mktemp_file() {
|
||||||
|
tmp=$(mktemp)
|
||||||
|
if ! test -f "${tmp}"; then
|
||||||
|
> "${tmp}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
validate_test_arg() {
|
validate_test_arg() {
|
||||||
# Must be a file or directory
|
# Must be a file or directory
|
||||||
if [ ! -e "${1}" ]; then
|
if [ ! -e "${1}" ]; then
|
||||||
|
@ -102,15 +119,7 @@ validate_test_arg() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# All temporary files go here
|
# All temporary files go here
|
||||||
urchin_tmp=$(mktemp)
|
urchin_tmp=$(mktemp_dir)
|
||||||
|
|
||||||
# Support HP-UX mktemp that has wrong exit codes and
|
|
||||||
# can't make directories.
|
|
||||||
if test -f "${urchin_tmp}"; then
|
|
||||||
rm "${urchin_tmp}"
|
|
||||||
fi
|
|
||||||
mkdir "${urchin_tmp}"
|
|
||||||
|
|
||||||
> "${urchin_tmp}/log"
|
> "${urchin_tmp}/log"
|
||||||
|
|
||||||
urchin_exit() {
|
urchin_exit() {
|
||||||
|
@ -385,7 +394,7 @@ report_outcome() {
|
||||||
|
|
||||||
# Use a temporary file rather than a pipe because a pipe starts a sub-shell
|
# Use a temporary file rather than a pipe because a pipe starts a sub-shell
|
||||||
# and thus makes the above variables local.
|
# and thus makes the above variables local.
|
||||||
sorted_log_file=$(mktemp)
|
sorted_log_file=$(mktemp_file)
|
||||||
cat "${log_file}" | LC_COLLATE=C sort > "${sorted_log_file}"
|
cat "${log_file}" | LC_COLLATE=C sort > "${sorted_log_file}"
|
||||||
|
|
||||||
while read line; do
|
while read line; do
|
||||||
|
|
Loading…
Reference in New Issue