gzip/tempfile.diff

45 lines
1.3 KiB
Diff
Raw Normal View History

--- zdiff.in
+++ zdiff.in
@@ -59,12 +59,12 @@
case "$2" in
*[-.]gz* | *[-.][zZ] | *.t[ga]z)
F=`echo "$2" | sed 's|.*/||;s|[-.][zZtga]*||'`
- set -C
- trap 'rm -f /tmp/"$F".$$; exit 2' HUP INT PIPE TERM 0
- gzip -cdfq -- "$2" > /tmp/"$F".$$ || exit
- gzip -cdfq -- "$1" | $comp $OPTIONS - /tmp/"$F".$$
+ TF=`/bin/mktemp -t "$F".XXXXXXXX` || exit 1
+ trap 'rm -f "$TF"; exit 2' HUP INT PIPE TERM 0
+ gzip -cdfq -- "$2" > "$TF" || exit
+ gzip -cdfq -- "$1" | $comp $OPTIONS - "$TF"
STAT="$?"
- /bin/rm -f /tmp/"$F".$$ || STAT=2
+ /bin/rm -f "$TF" || STAT=2
trap - HUP INT PIPE TERM 0
exit $STAT;;
--- znew.in
+++ znew.in
@@ -56,8 +56,9 @@
# block is the disk block size (best guess, need not be exact)
warn="(does not preserve modes and timestamp)"
-tmp=/tmp/zfoo.$$
-set -C
+dtmp=`mktemp -d -t znew.XXXXXXXX` || exit
+trap 'rm -rf $dtmp' HUP INT PIPE TERM 0
+tmp=$dtmp/znew
echo hi > $tmp || exit
if test -z "`(${CPMOD-cpmod} $tmp $tmp) 2>&1`"; then
cpmod=${CPMOD-cpmod}
@@ -73,7 +74,8 @@
# check if GZIP env. variable uses -S or --suffix
gzip -q $tmp
ext=`echo $tmp* | sed "s|$tmp||"`
-rm -f $tmp*
+rm -f $dtmp
+trap - HUP INT PIPE TERM 0
if test -z "$ext"; then
echo znew: error determining gzip extension
exit 1