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.1 3 Sep 2011 22:59:08 -0000 1.34
+++ cpio.1 25 May 2012 12:29:34 -0000
@@ -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.c 4 Mar 2012 04:05:15 -0000 1.75
+++ options.c 25 May 2012 12:29:34 -0000
@@ -81,6 +81,7 @@
#define GZIP_CMD "gzip" /* command to run as gzip */
#define COMPRESS_CMD "compress" /* command to run as compress */
#define BZIP2_CMD "bzip2" /* command to run as bzip2 */
+#define XZ_CMD "xz" /* 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)
{
(void)fputs(
- "usage: tar {crtux}[014578befHhjLmNOoPpqsvwXZz]\n"
+ "usage: tar {crtux}[014578befHhJjLmNOoPpqsvwXZz]\n"
" [blocking-factor | archive | replstr] [-C
directory] [-I file]\n"
" [file ...]\n"
- " tar {-crtux} [-014578eHhjLmNOoPpqvwXZz] [-b
blocking-factor]\n"
+ " tar {-crtux} [-014578eHhJjLmNOoPpqvwXZz] [-b
blocking-factor]\n"
" [-C directory] [-f archive] [-I file] [-s replstr]
[file ...]\n",
stderr);
exit(1);
@@ -1599,9 +1618,9 @@
cpio_usage(void)
{
(void)fputs(
- "usage: cpio -o [-AaBcjLvZz] [-C bytes] [-F archive] [-H format]\n"
+ "usage: cpio -o [-AaBcJjLvZz] [-C bytes] [-F archive] [-H
format]\n"
" [-O archive] < name-list [> archive]\n"
- " cpio -i [-6BbcdfjmrSstuvZz] [-C bytes] [-E file] [-F
archive] [-H format]\n"
+ " cpio -i [-6BbcdfJjmrSstuvZz] [-C bytes] [-E file] [-F
archive] [-H format]\n"
" [-I archive] [pattern ...] [< archive]\n"
" cpio -p [-adLlmuv] destination-directory < name-list\n",
stderr);
Index: pax.1
===================================================================
RCS file: /cvs/src/bin/pax/pax.1,v
retrieving revision 1.61
diff -u -r1.61 pax.1
--- pax.1 19 Sep 2010 20:55:25 -0000 1.61
+++ pax.1 25 May 2012 12:29:34 -0000
@@ -43,7 +43,7 @@
.Sh SYNOPSIS
.Bk -words
.Nm pax
-.Op Fl 0cdjnOvz
+.Op Fl 0cdJjnOvz
.Op Fl E Ar limit
.Op Fl f Ar archive
.Op Fl G Ar group
@@ -53,7 +53,7 @@
.Op Ar pattern ...
.Nm pax
.Fl r
-.Op Fl 0cDdijknOuvYZz
+.Op Fl 0cDdiJjknOuvYZz
.Op Fl E Ar limit
.Op Fl f Ar archive
.Op Fl G Ar group
@@ -65,7 +65,7 @@
.Op Ar pattern ...
.Nm pax
.Fl w
-.Op Fl 0adHijLOPtuvXz
+.Op Fl 0adHiJjLOPtuvXz
.Op Fl B Ar bytes
.Op Fl b Ar blocksize
.Op Fl f Ar archive
@@ -78,7 +78,7 @@
.Op Ar
.Nm pax
.Fl rw
-.Op Fl 0DdHijkLlnOPtuvXYZ
+.Op Fl 0DdHiJjkLlnOPtuvXYZ
.Op Fl G Ar group
.Op Fl p Ar string
.Op Fl s Ar replstr
@@ -447,6 +447,11 @@
The bzip2 utility must be installed separately.
Incompatible with
.Fl a .
+.It Fl J
+Use xz to compress (decompress) the archive while writing (reading).
+The xz utility must be installed separately.
+Incompatible with
+.Fl a .
.It Fl k
Do not overwrite existing files.
.It Fl L
@@ -950,6 +955,7 @@
The options that operate on the names of files or archive members
.Po Fl c ,
.Fl i ,
+.Fl J ,
.Fl j ,
.Fl n ,
.Fl s ,
@@ -1149,7 +1155,7 @@
specification.
.Pp
The flags
-.Op Fl 0BDEGjOPTUYZz ,
+.Op Fl 0BDEGJjOPTUYZz ,
the archive formats
.Em bcpio ,
.Em sv4cpio ,
Index: tar.1
===================================================================
RCS file: /cvs/src/bin/pax/tar.1,v
retrieving revision 1.55
diff -u -r1.55 tar.1
--- tar.1 2 Dec 2010 04:08:27 -0000 1.55
+++ tar.1 25 May 2012 12:29:34 -0000
@@ -32,7 +32,7 @@
.Sh SYNOPSIS
.Nm tar
.Sm off
-.No { Cm crtux No } Op Cm 014578befHhjLmNOoPpqsvwXZz
+.No { Cm crtux No } Op Cm 014578befHhJjLmNOoPpqsvwXZz
.Sm on
.Bk -words
.Op Ar blocking-factor | archive | replstr
@@ -43,7 +43,7 @@
.Nm tar
.No { Ns Fl crtux Ns }
.Bk -words
-.Op Fl 014578eHhjLmNOoPpqvwXZz
+.Op Fl 014578eHhJjLmNOoPpqvwXZz
.Op Fl b Ar blocking-factor
.Op Fl C Ar directory
.Op Fl f Ar archive
@@ -160,6 +160,9 @@
.It Fl j
Compress archive using bzip2.
The bzip2 utility must be installed separately.
+.It Fl J
+Compress archive using xz.
+The xz utility must be installed separately.
.It Fl L
Synonym for the
.Fl h
@@ -384,6 +387,7 @@
Keith Muller at the University of California, San Diego.
.Sh CAVEATS
The
+.Fl J ,
.Fl j
and
.Fl L