Skip to content

Commit 3c5c7d1

Browse files
committed
Remove dependency on 'mktemp'
1 parent c914037 commit 3c5c7d1

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

git-fmt-diff

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# globals {{{
77

88
gc_prog_name="fmt-diff"
9-
gc_version="1.0.1"
9+
gc_version="1.0.1-1-gc914037+1"
1010

1111
g_cached_opt=
1212

@@ -62,6 +62,51 @@ debug () (
6262
"$(basename "$0")" "${BASH_LINENO[0]}" "${FUNCNAME[1]}"'()' "$*"
6363
)
6464

65+
mk_tmp () (
66+
if [ -z "$TMPDIR" ]; then
67+
debug "TMPDIR not set"
68+
fi
69+
70+
if [ ! -d "$TMPDIR" ]; then
71+
debug "TMPDIR=$TMPDIR doesn't exist"
72+
mkdir -p "$TMPDIR"
73+
if [ ! -d "$TMPDIR" ]; then
74+
debug "unable to create $TMPDIR"
75+
return 1
76+
fi
77+
fi
78+
79+
tmp="$TMPDIR"
80+
while [ -e "$tmp" ]; do
81+
tmp="${TMPDIR:-/tmp}"/"$(sh -c 'echo "$$"')"
82+
done
83+
84+
cmd="touch"
85+
while [ "$#" -gt 0 ]; do
86+
case "$1" in
87+
-u) cmd= ;;
88+
-d) cmd="mkdir" ;;
89+
--suffix) tmp="$tmp$2" && shift ;;
90+
-p) debug "option '-p' not supported" && shift ;;
91+
-?*) debug "option '$1' not supported" ;;
92+
?*) debug "custom TEMPLATE not supported" ;;
93+
esac
94+
shift
95+
done
96+
97+
if [ -n "$cmd" ]; then
98+
$cmd "$tmp"
99+
if [ -e "$tmp" ]; then
100+
debug "tmp = $tmp"
101+
else
102+
debug "unable to create tmp = $tmp"
103+
return 1
104+
fi
105+
fi
106+
107+
echo "$tmp"
108+
)
109+
65110
pat_list_to_case () {
66111
sed 's/\s*,\s*/|/g'
67112
}
@@ -379,7 +424,7 @@ process_file () (
379424
return
380425
fi
381426

382-
tempdir="$(mktemp -d)"
427+
tempdir="$(mk_tmp -d)"
383428
rm_list__push "$tempdir"
384429

385430
debug "$b_name => $tempdir"
@@ -424,7 +469,7 @@ process_file () (
424469
)
425470

426471
processing () (
427-
outdir="$(mktemp -d)"
472+
outdir="$(mk_tmp -d --suffix '.out')"
428473
rm_list__push "$outdir"
429474
debug "OUTDIR: $outdir"
430475

@@ -433,7 +478,7 @@ processing () (
433478
repo_root="$(git rev-parse --show-toplevel 2> /dev/null)"
434479
[ -n "$repo_root" ] && { cd "$repo_root" || exit 1; }
435480

436-
risky="$outdir"/0
481+
risky="$outdir"/0.risky.list
437482
touch "$risky"
438483
rm_list__push "$risky"
439484

@@ -578,10 +623,11 @@ repo_root="$(git rev-parse --show-toplevel 2> /dev/null)"
578623
# setup env {{{2
579624
TMPDIR="${TMPDIR:-/tmp}"/git-"$gc_prog_name"
580625
mkdir -p "$TMPDIR"
581-
g_rm_list="$(mktemp)"
626+
g_rm_list="$(mk_tmp --suffix '.rm.list')"
582627
rm_list__push "$TMPDIR"
583628
rm_list__push "$g_rm_list"
584629

630+
# something for Windows... forgot what exactly...
585631
pwd -W > /dev/null 2>&1 && TMPDIR="$(cd "$TMPDIR" && pwd -W)"
586632

587633
export LESS="R$LESS"

0 commit comments

Comments
 (0)