bug-gzip
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

misc zgrep patches


From: Mike Frysinger
Subject: misc zgrep patches
Date: Thu, 7 Dec 2006 08:32:50 -0500
User-agent: KMail/1.9.5

we use a patch in Gentoo to change tempfiles from .$$ to `mktemp` ... any 
interest in this ?

also, Fedora has a patch to catch SIGPIPE's and handle them properly
-mike

Attachment: pgpZnI5YfKXDe.pgp
Description: PGP signature

--- gzip-1.3.1/zgrep.in
+++ gzip-1.3.1/zgrep.in
@@ -92,6 +92,7 @@
 fi
 
 res=0
+trap break SIGPIPE
 for i do
   gzip -cdfq "$i" |
     if test $files_with_matches -eq 1; then
@@ -110,5 +111,8 @@
     fi
   r=$?
   test $res -lt $r && res=$r
+  # SIGPIPE + 128
+  test "$r" -eq 141 && exit $res
 done
+trap - SIGPIPE
 exit $res
--- znew.in.orig        2004-12-12 23:22:11.668680240 -0500
+++ znew.in     2004-12-12 23:23:48.827909792 -0500
@@ -14,7 +14,7 @@
 # block is the disk block size (best guess, need not be exact)
 
 warn="(does not preserve modes and timestamp)"
-tmp=/tmp/zfoo.$$
+tmp=`mktemp /tmp/zfoo.XXXXXX`
 set -C
 echo hi > $tmp.1 || exit 1
 echo hi > $tmp.2 || exit 1
@@ -77,6 +77,7 @@
 
 for i do
   n=`echo $i | sed 's/.Z$//'`
+  ntmp=`mktemp $n.XXXXXX`
   if test ! -f "$n.Z" ; then
     echo $n.Z not found
     res=1; continue
@@ -92,7 +93,7 @@
     fi
   else
     if test $check -eq 1; then
-      if cp -p "$n.Z" "$n.$$" 2> /dev/null || cp "$n.Z" "$n.$$"; then
+      if cp -p "$n.Z" "$ntmp" 2> /dev/null || cp "$n.Z" "$ntmp"; then
        :
       else
        echo cannot backup "$n.Z"
@@ -102,7 +103,7 @@
     if gzip -d "$n.Z"; then
       :
     else
-      test $check -eq 1 && mv "$n.$$" "$n.Z"
+      test $check -eq 1 && mv "$ntmp" "$n.Z"
       echo error while uncompressing $n.Z
       res=1; continue
     fi
@@ -110,7 +111,7 @@
       :
     else
       if test $check -eq 1; then
-       mv "$n.$$" "$n.Z" && rm -f "$n"
+       mv "$ntmp" "$n.Z" && rm -f "$n"
         echo error while recompressing $n
       else
        # compress $n  (might be dangerous if disk full)
@@ -125,7 +126,7 @@
     if test $pipe -eq 1; then
       rm -f "$n$ext"
     elif test $check -eq 1; then
-      mv "$n.$$" "$n.Z" && rm -f "$n$ext"
+      mv "$ntmp" "$n.Z" && rm -f "$n$ext"
     else
       gzip -d "$n$ext" && compress "$n" && rm -f "$n$ext"
     fi
@@ -133,9 +134,9 @@
 
   elif test $check -eq 1; then
     if gzip -t "$n$ext" ; then
-      rm -f "$n.$$" "$n.Z"
+      rm -f "$ntmp" "$n.Z"
     else
-      test $pipe -eq 0 && mv "$n.$$" "$n.Z"
+      test $pipe -eq 0 && mv "$ntmp" "$n.Z"
       rm -f "$n$ext"
       echo error while testing $n$ext, $n.Z unchanged
       res=1; continue
@@ -144,4 +145,5 @@
     rm -f "$n.Z"
   fi
 done
+rm -f "$ntmp"
 exit $res

reply via email to

[Prev in Thread] Current Thread [Next in Thread]