I thought you might be interested in one of my "Can't live without this
anymore" patches. Enjoy.

MSB
Submitted By: Matthias S. Benkmann <article AT winterdrache DOT de>
Date: 2006-07-18
Initial Package Version: 1.15.1
Origin: Matthias S. Benkmann
Description: 
  tar xzf foo.tar.bz2  - if you don't see what's wrong with this, you need
  this patch. It makes the "z" option behave like "j" if the archive name
  given ends in ".bz2". IOW, forget "j", always use "z".


diff -Naur tar-1.15.1/src/common.h tar-1.15.1-bz2-autodetect/src/common.h
--- tar-1.15.1/src/common.h     Tue Dec 21 15:31:58 2004
+++ tar-1.15.1-bz2-autodetect/src/common.h      Thu May 25 14:58:07 2006
@@ -147,6 +147,12 @@
 /* Specified name of compression program, or "gzip" as implied by -z.  */
 GLOBAL const char *use_compress_program_option;
 
+/* User passed z option on command line */
+GLOBAL bool z_option_used;
+
+/* Archive name (f option) ends in ".bz2" */
+GLOBAL bool archive_is_bz2;
+
 GLOBAL bool dereference_option;
 
 /* Print a message if not all links are dumped */
diff -Naur tar-1.15.1/src/tar.c tar-1.15.1-bz2-autodetect/src/tar.c
--- tar-1.15.1/src/tar.c        Tue Dec 21 15:11:26 2004
+++ tar-1.15.1-bz2-autodetect/src/tar.c Thu May 25 15:09:38 2006
@@ -19,6 +19,9 @@
    with this program; if not, write to the Free Software Foundation, Inc.,
    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
+/* Patch from http://www.winterdrache.de applied to select bzip2 if 
+   z parameter specified but extension is .bz2 */
+
 #include <system.h>
 
 #include <fnmatch.h>
@@ -671,6 +674,12 @@
            xrealloc (archive_name_array,
                      sizeof (const char *) * allocated_archive_names);
        }
+
+       {
+          ssize_t len=strlen(arg);
+          if (len>=4 && strcmp(arg+len-4,".bz2")==0) archive_is_bz2 = true;
+       }
+
       archive_name_array[archive_names++] = arg;
       break;
 
@@ -908,6 +917,7 @@
       
     case 'z':
       set_use_compress_program_option ("gzip");
+      z_option_used = true;
       break;
       
     case 'Z':
@@ -1269,6 +1279,9 @@
     default:
       return ARGP_ERR_UNKNOWN;
     }
+    
+      
+    
   return 0;
 }
 
@@ -1397,6 +1410,8 @@
                  &index, &args))
     exit (1);
       
+  /* if z was specified but filename ends in bz2, then use bzip2 */
+    if (z_option_used && archive_is_bz2) use_compress_program_option="bzip2";
 
   /* Special handling for 'o' option:
 
-- 
http://linuxfromscratch.org/mailman/listinfo/patches
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to