[BusyBox] new tar patch, want to get this out of the way

Matt Kraai kraai at alumni.carnegiemellon.edu
Wed Oct 3 09:57:20 UTC 2001


On Wed, Oct 03, 2001 at 05:44:28PM +1000, Glenn McGrath wrote:
> Ive had these tar changes for a few months now, it would be good to get it
> out of the way.
> 
> The drop in replacement for tar can be found at
> http://people.debian.org/~bug1/busybox/tar.0310.c

There are a number of bugs in this reimplementation:

	* It doesn't behave correctly if the first argument isn't
	  preceded by a `-'.

	* It sets the file_list_name for `x', though it doesn't
	  take an argument.

	* It doesn't complain if the number of [ctx] options isn't
	  1.

	* It doesn't handle multiple [TX] options correctly.

	* It doesn't handle mixed extraction/exclusion lists.

	* It doesn't handle the `cz' options correctly.

The following patch fixes the first three problems.  It doesn't
address the last three, however.  Care to fix them and resubmit?

As an aside, even my minimal test suite caught the first problem.
I've posted a new test suite[1] which tests for all but the second
problem.

Matt

1. http://busybox.net/~kraai/testsuite-0.1.4.tar.gz

--- tar.0310.c	Wed Oct  3 00:34:25 2001
+++ tar.c	Wed Oct  3 09:56:24 2001
@@ -510,7 +510,9 @@
 		untar_from_file = 1,
 		untar_from_stdin = 2,
 		untar_create = 4,
-		untar_unzip = 8
+		untar_list = 8,
+		untar_extract = 16,
+		untar_unzip = 32
 	};
 	FILE *src_stream = NULL;
 	FILE *uncompressed_stream = NULL;
@@ -528,7 +530,14 @@
 	if (argc < 2) {
 		show_usage();
 	}
-	
+
+	if (argv[1][0] != '-') {
+		char *tmp = xmalloc(strlen(argv[1]) + 2);
+		tmp[0] = '-';
+		strcpy(tmp + 1, argv[1]);
+		argv[1] = tmp;
+	}
+
 	while ((opt = getopt(argc, argv, "cC:f:T:OptvxX:z")) != -1) {
 		switch (opt) {
 		case 'c':
@@ -558,6 +567,7 @@
 			break;
 		case 't':
 			extract_function |= extract_list;
+			untar_funct |= untar_list;
 			break;
 		case 'v':
 			if (extract_function & extract_list) {
@@ -566,8 +576,8 @@
 			extract_function |= extract_list;
 			break;
 		case 'x':
-			file_list_name = xstrdup(optarg);
 			extract_function |= (extract_all_to_fs | extract_unconditional | extract_create_leading_dirs);
+			untar_funct |= untar_extract;
 			break;
 		case 'X':
 			file_list_name = xstrdup(optarg);
@@ -580,6 +590,12 @@
 			show_usage();
 		}
 	}
+
+	opt = untar_funct & (untar_create | untar_extract | untar_list);
+	if (! opt)
+		error_msg_and_die("You must specify one of the `ctx' options");
+	else if (opt != untar_create && opt != untar_extract && opt != untar_list)
+		error_msg_and_die("You may not specify more than one `ctx' option.");
 
 	/* Setup an array of filenames to work with */
 	num_of_entries = 0;





More information about the busybox mailing list