bug-tar
[Top][All Lists]
Advanced

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

[Bug-tar] [PATCH] automatically find and use compression filter + bzip2


From: Ingmar Schuster
Subject: [Bug-tar] [PATCH] automatically find and use compression filter + bzip2 filter
Date: Wed, 30 Jul 2003 12:42:50 +0200

Hi,

Yesterday I hacked tar-1.13 so that
"tar qxf somearchive.tar.gz"
and
"tar qcf somearchive.tar.bz2 SOME OTHER FILES"
and
"tar --auto-uncompr qf somearchive.tar.Z"
automatically determines the filter to use by looking at the filename.

the "patch -ru" is attached.

Greetings
Ingmar

______________________________________________________________________________
ComputerBild 15-03 bestaetigt: Den besten Spam-Schutz gibt es bei 
WEB.DE FreeMail - Deutschlands beste E-Mail - http://s.web.de/?mc=021121
diff -ur ./src/buffer.c ../tar-1.13_modified/src/buffer.c
--- ./src/buffer.c      Mon Jul  5 08:47:59 1999
+++ ../tar-1.13_modified/src/buffer.c   Tue Jul 29 22:02:02 2003
@@ -725,6 +725,29 @@
   if (multi_volume_option && verify_option)
     FATAL_ERROR ((0, 0, _("Cannot verify multi-volume archives")));
 
+  if (use_compress_program_option_auto)
+    {
+      int len_ending = 0;
+      int len_fname = 0;
+      int i = 0;
+      char *ending[] = {"gz","gzip", /* tgz is recognized by this, too */
+                       "Z","compress",
+                       "bz2","bzip2"
+                       "\0", "\0"};
+
+      len_fname = strlen (archive_name_array[0]) ;
+      for (i = 0; ending[i][0] != '\0'; i += 2)
+      {
+        len_ending = strlen (ending[i]);
+        if (!strcmp (archive_name_array[0] + len_fname - len_ending, 
ending[i]))
+        {
+          use_compress_program_option = strdup (ending[i+1]);
+          break;
+        }
+      }
+    }
+
+
   if (use_compress_program_option)
     {
       if (multi_volume_option)
diff -ur ./src/common.h ../tar-1.13_modified/src/common.h
--- ./src/common.h      Wed Jul  7 08:07:30 1999
+++ ../tar-1.13_modified/src/common.h   Tue Jul 29 23:01:25 2003
@@ -137,6 +137,9 @@
 /* Boolean value.  */
 GLOBAL int checkpoint_option;
 
+/* Boolean value.  */
+GLOBAL int use_compress_program_option_auto;
+
 /* Specified name of compression program, or "gzip" as implied by -z.  */
 GLOBAL const char *use_compress_program_option;
 
diff -ur ./src/tar.c ../tar-1.13_modified/src/tar.c
--- ./src/tar.c Wed Jul  7 07:49:50 1999
+++ ../tar-1.13_modified/src/tar.c      Tue Jul 29 23:04:58 2003
@@ -159,11 +159,15 @@
   {"after-date", required_argument, NULL, 'N'},
   {"append", no_argument, NULL, 'r'},
   {"atime-preserve", no_argument, &atime_preserve_option, 1},
+  {"auto-uncompr", no_argument, NULL, 'q'},
+  {"auto-compr", no_argument, NULL, 'q'},
   {"backup", optional_argument, NULL, BACKUP_OPTION},
   {"block-compress", no_argument, NULL, OBSOLETE_BLOCK_COMPRESS},
   {"block-number", no_argument, NULL, 'R'},
   {"block-size", required_argument, NULL, OBSOLETE_BLOCKING_FACTOR},
   {"blocking-factor", required_argument, NULL, 'b'},
+  {"bzip2", no_argument, NULL, 'j'},
+  {"bunzip2", no_argument, NULL, 'j'},
   {"catenate", no_argument, NULL, 'A'},
   {"checkpoint", no_argument, &checkpoint_option, 1},
   {"compare", no_argument, NULL, 'd'},
@@ -340,6 +344,8 @@
               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\
+  -q, --auto-compr, --auto-uncompr   automatically find filter by filename\n\
+  -j, --bzip2, --bunzip2             filter the archive through bzip2\n\
   -z, --gzip, --ungzip               filter the archive through gzip\n\
   -Z, --compress, --uncompress       filter the archive through compress\n\
       --use-compress-program=PROG    filter through PROG (must accept -d)\n"),
@@ -410,13 +416,13 @@
 | Parse the options for tar.  |
 `----------------------------*/
 
-/* Available option letters are DEHIJQY and aejnqy.  Some are reserved:
+/* Available option letters are DEHIJQY and aeny.  Some are reserved:
 
    y  per-file gzip compression
    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:hijklmopqrstuvwxz"
 
 static void
 set_subcommand_option (enum subcommand subcommand)
@@ -633,6 +639,10 @@
        ignore_zeros_option = 1;
        break;
 
+      case 'j':
+       set_use_compress_program_option ("bzip2");
+       break;
+
       case 'k':
        /* Don't overwrite existing files.  */
 
@@ -716,6 +726,10 @@
       case 'P':
        absolute_names_option = 1;
        break;
+
+      case 'q':
+       use_compress_program_option_auto = 1;
+       break;      
 
       case 'r':
        set_subcommand_option (APPEND_SUBCOMMAND);

reply via email to

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