tech-userlevel archive

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

[patch] tar: short option for xz (de)compression



Hello,

I'm quite new to NetBSD. One small detail I'm missing, is a quick way
to extract *.tar.xz (or *.tar.lzma) archives. I got used to the option
'-J' present in GNU tar (FreeBSD tar has it, too):

  tar cJf archive.tar.xz dir

  tar xJf archive.tar.xz

It's not a big deal to enable it in NetBSD, as there is already the
long option --xz. Please have a look at the attached patch. What do you
think?

Regards,
Jo.
Index: bin/pax/options.c
===================================================================
RCS file: /cvsroot/src/bin/pax/options.c,v
retrieving revision 1.115
diff -u -r1.115 options.c
--- bin/pax/options.c	14 Nov 2013 04:00:48 -0000	1.115
+++ bin/pax/options.c	4 Apr 2015 15:47:53 -0000
@@ -773,6 +773,7 @@
 	{ "gunzip",		no_argument,		0,	'z' },
 	{ "read-full-blocks",	no_argument,		0,	'B' },
 	{ "directory",		required_argument,	0,	'C' },
+	{ "xz",			no_argument,		0,	'J' },
 	{ "to-stdout",		no_argument,		0,	'O' },
 	{ "absolute-paths",	no_argument,		0,	'P' },
 	{ "sparse",		no_argument,		0,	'S' },
@@ -798,8 +799,6 @@
 						OPT_EXCLUDE },
 	{ "no-recursion",	no_argument,		0,
 						OPT_NORECURSE },
-	{ "xz",			no_argument,		0,
-						OPT_XZ },
 #if !HAVE_NBTOOL_CONFIG_H
 	{ "chroot",		no_argument,		0,
 						OPT_CHROOT },
@@ -877,7 +876,7 @@
 	 * process option flags
 	 */
 	while ((c = getoldopt(argc, argv,
-	    "+b:cef:hjklmopqrs:tuvwxzBC:HI:OPST:X:Z014578",
+	    "+b:cef:hjklmopqrs:tuvwxzBC:HI:JOPST:X:Z014578",
 	    tar_longopts, NULL))
 	    != -1)  {
 		switch(c) {
@@ -966,9 +965,6 @@
 				nopids = 1;
 			}
 			break;
-		case 'O':
-			Oflag = 1;
-			break;
 		case 'p':
 			/*
 			 * preserve user id, group id, file
@@ -1064,6 +1060,12 @@
 			incfiles[nincfiles - 1].file = optarg;
 			incfiles[nincfiles - 1].dir = chdname;
 			break;
+		case 'J':
+			gzip_program = XZ_CMD;
+			break;
+		case 'O':
+			Oflag = 1;
+			break;
 		case 'P':
 			/*
 			 * do not remove leading '/' from pathnames
@@ -1142,9 +1144,6 @@
 			do_chroot = 1;
 			break;
 #endif
-		case OPT_XZ:
-			gzip_program = XZ_CMD;
-			break;
 		default:
 			tar_usage();
 			break;
@@ -2134,8 +2133,8 @@
 static void
 tar_usage(void)
 {
-	(void)fputs("usage: tar [-]{crtux}[-befhjklmopqvwzHOPSXZ014578] [archive] "
-		    "[blocksize]\n"
+	(void)fputs("usage: tar [-]{crtux}[-befhjklmopqvwzHJOPSXZ014578] "
+		    "[archive] [blocksize]\n"
 		    "           [-C directory] [-T file] [-s replstr] "
 		    "[file ...]\n", stderr);
 	exit(1);
Index: bin/pax/tar.1
===================================================================
RCS file: /cvsroot/src/bin/pax/tar.1,v
retrieving revision 1.33
diff -u -r1.33 tar.1
--- bin/pax/tar.1	22 Mar 2012 07:58:17 -0000	1.33
+++ bin/pax/tar.1	4 Apr 2015 15:47:53 -0000
@@ -34,7 +34,7 @@
 .Sh SYNOPSIS
 .Nm tar
 .Sm off
-.Oo \&- Oc {crtux} Op Fl 014578befHhjklmOoPpqSvwXZz
+.Oo \&- Oc {crtux} Op Fl 014578befHhJjklmOoPpqSvwXZz
 .Sm on
 .Op Ar archive
 .Op Ar blocksize
@@ -107,6 +107,9 @@
 .It Fl h , Fl Fl dereference
 Follow symbolic links as if they were normal files
 or directories.
+.It Fl J, Fl Fl xz
+Compress/decompress archive using 
+.Xr xz 1 .
 .It Fl j, Fl Fl bzip2, Fl Fl bunzip2
 Use
 .Xr bzip2 1
@@ -209,9 +212,6 @@
 .Nm
 to prompt the user for the filename to use when storing or
 extracting files in an archive.
-.It Fl Fl xz
-Compress/decompress archive using 
-.Xr xz 1 .
 .It Fl z , Fl Fl gzip , Fl Fl gunzip
 Compress/decompress archive using
 .Xr gzip 1 .


Home | Main Index | Thread Index | Old Index