aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2014-11-10 18:54:40 +0200
committerLasse Collin <lasse.collin@tukaani.org>2014-11-10 18:54:40 +0200
commit7b03a15cea8cd4f19ed680b51c4bcbae3ce4142f (patch)
tree73e6abf722be50f71c92537c60a62514d845014e
parentxzdiff: Create a temporary directory to hold a temporary file. (diff)
downloadxz-7b03a15cea8cd4f19ed680b51c4bcbae3ce4142f.tar.xz
xzdiff: Use mkdir if mktemp isn't available.
-rw-r--r--src/scripts/xzdiff.in17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/scripts/xzdiff.in b/src/scripts/xzdiff.in
index ea35d26b..79df3836 100644
--- a/src/scripts/xzdiff.in
+++ b/src/scripts/xzdiff.in
@@ -139,7 +139,22 @@ elif test $# -eq 2; then
test -n "$tmp" && rm -rf "$tmp"
(exit 2); exit 2
' HUP INT PIPE TERM 0
- tmp=`mktemp -t -d -- "$prog.XXXXXXXXXX"` || exit 2
+ if type mktemp >/dev/null 2>&1; then
+ tmp=`mktemp -t -d -- "$prog.XXXXXXXXXX"` || exit 2
+ else
+ # Fallback code if mktemp is missing. This isn't as
+ # robust as using mktemp since this doesn't try with
+ # different file names in case of a file name conflict.
+ #
+ # There's no need to save the original umask since
+ # we don't create any non-temp files. Note that using
+ # mkdir -m 0077 isn't secure since some mkdir implementations
+ # create the dir with the default umask and chmod the
+ # the dir afterwards.
+ umask 0077
+ mkdir -- "${TMPDIR-/tmp}/$prog.$$" || exit 2
+ tmp="${TMPDIR-/tmp}/$prog.$$"
+ fi
$xz2 -cdfq -- "$2" > "$tmp/$F" || exit 2
xz_status=$(
exec 4>&1