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)
{