Re: tar -J to extract xz archives

2012-05-30 Thread Gabriel Linder

On 05/30/12 07:53, Landry Breuil wrote:

On Tue, May 29, 2012 at 09:19:49PM -0400, Ted Unangst wrote:

On Tue, May 29, 2012 at 17:46, Gabriel Linder wrote:

I see more and more tar.xz archives, and thought it would be nice to
have tar able to extract them directly as with gzip/bzip2.

-J is what GNU and FreeBSD use, so I used it too. Based on what was done
to add bzip2 support.

So I never quite finished it in time before the -j patch went in, but
I think tar should just auto detect the compression and use the right
program.  It requires reading about two bytes out of the stream.  It's
a little tricky if the data is piped in, but I don't think it's
intractable.

So -z would just always do the right thing.  I think that's a better
way to do it.

Not an argument per se, but gtar uses -a/--auto-compress for that
mode. And it even see to be default if no compression scheme is
specified, ie 'gtar tf' and 'gtar xf' do the right thing (tm). See
http://petereisentraut.blogspot.com/2012/05/time-to-retrain-fingers.html
and the associated comments..

Landry


That would be nice, I think. FreeBSD version seem able to do that too, 
from their manpage.




tar -J to extract xz archives

2012-05-29 Thread Gabriel Linder
I see more and more tar.xz archives, and thought it would be nice to 
have tar able to extract them directly as with gzip/bzip2.


-J is what GNU and FreeBSD use, so I used it too. Based on what was done 
to add bzip2 support.


In case my client mess up with tabulations, here is a real file : 
http://dargor.servebeer.com/~dargor/openbsd/pax+xz.diff




Index: cpio.1
===
RCS file: /cvs/src/bin/pax/cpio.1,v
retrieving revision 1.34
diff -u -r1.34 cpio.1
--- cpio.13 Sep 2011 22:59:08 -1.34
+++ cpio.125 May 2012 12:29:34 -
@@ -32,7 +32,7 @@
 .Sh SYNOPSIS
 .Nm cpio
 .Fl o
-.Op Fl AaBcjLvZz
+.Op Fl AaBcJjLvZz
 .Op Fl C Ar bytes
 .Op Fl F Ar archive
 .Op Fl H Ar format
@@ -41,7 +41,7 @@
 .Op \*(Gt Ar archive
 .Nm cpio
 .Fl i
-.Op Fl 6BbcdfjmrSstuvZz
+.Op Fl 6BbcdfJjmrSstuvZz
 .Op Fl C Ar bytes
 .Op Fl E Ar file
 .Op Fl F Ar archive
@@ -110,6 +110,9 @@
 .It Fl j
 Compress archive using the bzip2 format.
 The bzip2 utility must be installed separately.
+.It Fl J
+Compress archive using the xz format.
+The xz utility must be installed separately.
 .It Fl L
 Follow symbolic links.
 .It Fl O Ar archive
@@ -185,6 +188,9 @@
 .It Fl j
 Uncompress archive using the bzip2 format.
 The bzip2 utility must be installed separately.
+.It Fl J
+Uncompress archive using the xz format.
+The xz utility must be installed separately.
 .It Fl m
 Restore modification times on files.
 .It Fl r
Index: options.c
===
RCS file: /cvs/src/bin/pax/options.c,v
retrieving revision 1.75
diff -u -r1.75 options.c
--- options.c4 Mar 2012 04:05:15 -1.75
+++ options.c25 May 2012 12:29:34 -
@@ -81,6 +81,7 @@
 #define GZIP_CMDgzip/* command to run as gzip */
 #define COMPRESS_CMDcompress/* command to run as compress */
 #define BZIP2_CMDbzip2/* command to run as bzip2 */
+#define XZ_CMDxz/* command to run as xz */

 /*
  *Format specific routine table - MUST BE IN SORTED ORDER BY NAME
@@ -192,7 +193,7 @@
 /*
  * process option flags
  */
-while 
((c=getopt(argc,argv,ab:cdf:ijklno:p:rs:tuvwx:zB:DE:G:HLOPT:U:XYZ0))
+while 
((c=getopt(argc,argv,ab:cdf:ijklno:p:rs:tuvwx:zB:DE:G:HJLOPT:U:XYZ0))

 != -1) {
 switch (c) {
 case 'a':
@@ -444,6 +445,12 @@
 Hflag = 1;
 flg |= CHF;
 break;
+case 'J':
+/*
+ * use xz.  Non standard option.
+ */
+gzip_program = XZ_CMD;
+break;
 case 'L':
 /*
  * follow symlinks
@@ -620,7 +627,7 @@
  * process option flags
  */
 while ((c = getoldopt(argc, argv,
-b:cef:hjmopqruts:vwxzBC:HI:LNOPXZ014578)) != -1) {
+b:cef:hjmopqruts:vwxzBC:HI:JLNOPXZ014578)) != -1) {
 switch (c) {
 case 'b':
 /*
@@ -779,6 +786,12 @@
 incfiles[nincfiles - 1].file = optarg;
 incfiles[nincfiles - 1].dir = chdname;
 break;
+case 'J':
+/*
+ * use xz.  Non standard option.
+ */
+gzip_program = XZ_CMD;
+break;
 case 'L':
 /*
  * follow symlinks
@@ -1053,7 +1066,7 @@
 dflag = 1;
 act = -1;
 nodirs = 1;
-while ((c=getopt(argc,argv,abcdfijklmoprstuvzABC:E:F:H:I:LO:SZ6)) 
!= -1)
+while 
((c=getopt(argc,argv,abcdfijklmoprstuvzABC:E:F:H:I:JLO:SZ6)) != -1)

 switch (c) {
 case 'a':
 /*
@@ -1224,6 +1237,12 @@
 (void)fputs(\n\n, stderr);
 cpio_usage();
 break;
+case 'J':
+/*
+ * use xz.  Non standard option.
+ */
+gzip_program = XZ_CMD;
+break;
 case 'L':
 /*
  * follow symbolic links
@@ -1559,11 +1578,11 @@
 pax_usage(void)
 {
 (void)fputs(
-usage: pax [-0cdjnOvz] [-E limit] [-f archive] [-G group] [-s 
replstr]\n
+usage: pax [-0cdJjnOvz] [-E limit] [-f archive] [-G group] [-s 
replstr]\n

[-T range] [-U user] [pattern ...]\n
-   pax -r [-0cDdijknOuvYZz] [-E limit] [-f archive] [-G 
group] [-o options]\n
+   pax -r [-0cDdiJjknOuvYZz] [-E limit] [-f archive] [-G 
group] [-o options]\n
[-p string] [-s replstr] [-T range] [-U user] 
[pattern ...]\n
-   pax -w [-0adHijLOPtuvXz] [-B bytes] [-b blocksize] [-f 
archive]\n
+   pax -w [-0adHiJjLOPtuvXz] [-B bytes] [-b blocksize] [-f 
archive]\n
[-G group] [-o options] [-s replstr] [-T range] 
[-U user]\n

[-x format] [file ...]\n
pax -rw [-0DdHikLlnOPtuvXYZ] [-G group] [-p string] 
[-s replstr]\n

@@ -1581,10 +1600,10 @@
 tar_usage(void)
 {
 

Re: tar -J to extract xz archives

2012-05-29 Thread Anthony J. Bentley
Gabriel Linder writes:
I see more and more tar.xz archives, and thought it would be nice to 
have tar able to extract them directly as with gzip/bzip2.

-J is what GNU and FreeBSD use, so I used it too. Based on what was done 
to add bzip2 support.

This has been discussed on the list before. I think the conclusion was
that xz won't make it into base, and adding new tar flags for stuff not
in base is a bad idea (although we already have -j for bzip2).

--
Anthony J. Bentley



Re: tar -J to extract xz archives

2012-05-29 Thread Marc Espie
On Tue, May 29, 2012 at 12:12:21PM -0600, Anthony J. Bentley wrote:
 Gabriel Linder writes:
 I see more and more tar.xz archives, and thought it would be nice to 
 have tar able to extract them directly as with gzip/bzip2.
 
 -J is what GNU and FreeBSD use, so I used it too. Based on what was done 
 to add bzip2 support.
 
 This has been discussed on the list before. I think the conclusion was
 that xz won't make it into base, and adding new tar flags for stuff not
 in base is a bad idea (although we already have -j for bzip2).
 
 --
 Anthony J. Bentley

xz has the added problem that it's totally C99 source, so it won't compile
with vax/sparc...



Re: tar -J to extract xz archives

2012-05-29 Thread Landry Breuil
On Tue, May 29, 2012 at 09:19:49PM -0400, Ted Unangst wrote:
 On Tue, May 29, 2012 at 17:46, Gabriel Linder wrote:
  I see more and more tar.xz archives, and thought it would be nice to
  have tar able to extract them directly as with gzip/bzip2.
  
  -J is what GNU and FreeBSD use, so I used it too. Based on what was done
  to add bzip2 support.
 
 So I never quite finished it in time before the -j patch went in, but
 I think tar should just auto detect the compression and use the right
 program.  It requires reading about two bytes out of the stream.  It's
 a little tricky if the data is piped in, but I don't think it's
 intractable.
 
 So -z would just always do the right thing.  I think that's a better
 way to do it.

Not an argument per se, but gtar uses -a/--auto-compress for that
mode. And it even see to be default if no compression scheme is
specified, ie 'gtar tf' and 'gtar xf' do the right thing (tm). See
http://petereisentraut.blogspot.com/2012/05/time-to-retrain-fingers.html
and the associated comments..

Landry