tar bzip2 auto-detect patch

Matthias Benkmann haferfrost at web.de
Thu Jul 19 12:49:45 PDT 2001


On 19 Jul 2001, at 16:11, Leonardo Valeri Manera wrote:

> Matthias Benkmann wrote:
> 
> 
> > Just apply the attached patch instead of the normal gnutarpatch.txt used
> > by LFS.
> 
> 
> i'd love to, but...where is the 'attached' patch? :)

Don't tell me your mail client can't handle 0-bit encoding :-)

Well, here is the patch in a more standard format.

MSB

----
Indecision is the key to flexibility.


-------------- next part --------------
--- tar.c.orig	Thu Jul 19 20:11:03 2001
+++ tar.c	Thu Jul 19 20:18:43 2001
@@ -16,6 +16,10 @@
    with this program; if not, write to the Free Software Foundation, Inc.,
    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
+/* Patched to integrate bzip2 as compression filter (option -y)  */
+
+/* Patched to select bzip2 if z parameter specified but extension is .bz2 */
+
 #include "system.h"
 
 #include <getopt.h>
@@ -164,6 +168,8 @@
   {"block-number", no_argument, NULL, 'R'},
   {"block-size", required_argument, NULL, OBSOLETE_BLOCKING_FACTOR},
   {"blocking-factor", required_argument, NULL, 'b'},
+  {"bunzip2", required_argument, NULL, 'y'},
+  {"bzip2", required_argument, NULL, 'y'},
   {"catenate", no_argument, NULL, 'A'},
   {"checkpoint", no_argument, &checkpoint_option, 1},
   {"compare", no_argument, NULL, 'd'},
@@ -340,7 +346,9 @@
               PATTERN                at list/extract time, a globbing PATTERN\n\
   -o, --old-archive, --portability   write a V7 format archive\n\
       --posix                        write a POSIX conformant archive\n\
-  -z, --gzip, --ungzip               filter the archive through gzip\n\
+  -y, --bzip2, --bunzip2             filter the archive through bzip2\n\
+  -z, --gzip, --ungzip               filter the archive through bzip2 if\n\
+                                     extension is .bz2 and gzip otherwise\n\
   -Z, --compress, --uncompress       filter the archive through compress\n\
       --use-compress-program=PROG    filter through PROG (must accept -d)\n"),
 	     stdout);
@@ -416,7 +424,7 @@
    Y  per-block gzip compression */
 
 #define OPTION_STRING \
-  "-01234567ABC:F:GK:L:MN:OPRST:UV:WX:Zb:cdf:g:hiklmoprstuvwxz"
+  "-01234567ABC:F:GK:L:MN:OPRST:UV:WX:Zb:cdf:g:hiklmoprstuvwxyz"
 
 static void
 set_subcommand_option (enum subcommand subcommand)
@@ -596,6 +604,10 @@
 	      xrealloc (archive_name_array,
 			sizeof (const char *) * allocated_archive_names);
 	  }
+	{
+	  ssize_t len=strlen(optarg);
+	  if (len>=4 && strcmp(optarg+len-4,".bz2")==0) archive_is_bz2=1;
+	}
 	archive_name_array[archive_names++] = optarg;
 	break;
 
@@ -788,8 +800,13 @@
 	  FATAL_ERROR ((0, errno, "%s", optarg));
 	break;
 
+      case 'y':
+	set_use_compress_program_option ("bzip2");
+	break;
+
       case 'z':
 	set_use_compress_program_option ("gzip");
+	z_option_used = 1;
 	break;
 
       case 'Z':
@@ -986,6 +1003,9 @@
 
 #endif /* not DEVICE_PREFIX */
       }
+
+  /* if z was specified but filename ends in bz2, then use bzip2 */
+  if (z_option_used && archive_is_bz2) use_compress_program_option="bzip2";
 
   /* Process trivial options.  */
 
--- common.h.orig	Thu Jul 19 20:11:33 2001
+++ common.h	Thu Jul 19 20:04:47 2001
@@ -141,6 +141,10 @@
 GLOBAL const char *use_compress_program_option;
 
 /* Boolean value.  */
+GLOBAL int z_option_used;
+GLOBAL int archive_is_bz2;
+
+/* Boolean value.  */
 GLOBAL int dereference_option;
 
 /* Patterns that match file names to be excluded.  */


More information about the lfs-dev mailing list