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

user/1434: tar -T option does not work properly




>Number:         1434
>Category:       user
>Synopsis:       tar -T option does not work properly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Oct  6 12:00:01 MDT 2000
>Last-Modified:
>Originator:     Erik Anggard
>Organization:
net
>Release:        OpenBSD cisb.devel.cygate.se 2.7 GENERIC#25 i386
>Environment:
	System      : OpenBSD 2.7
	Architecture: OpenBSD.i386
	Machine     : i386

>Description:
The command "tar -cf file.tar -T list" is supposed to create a tar-file 
containing all files listed in the file "list" but stops with an error:
tar: illegal option -- T

The same goes for extracting files with "tar -xf file.tar -T list".

The -T option will however work when some other file to add/extract is 
specified directly on the command line before the -T option.

>How-To-Repeat:
$ cd /tmp
$ echo "test" > file
$ echo "/tmp/file" > list
$ tar -cf test.tar -C / -T list
tar: illegal option -- T
usage: tar -{txru}[cevfbmopqswzBHLPXZ014578] [tapefile] [blocksize]
[replstr] [-C directory] [-T file] file1 file2...
$  

>Fix:
I wrote the following patch of /usr/src/bin/pax/options.c to fix the
problem:

--- options.c.org	Wed Oct  4 19:56:06 2000
+++ options.c	Thu Oct  5 20:03:02 2000
@@ -608,6 +608,7 @@
 	register int c;
 	int fstdin = 0;
 	int Oflag = 0;
+	int Tflag = 0;
 
 	/*
 	 * Set default values.
@@ -617,8 +618,8 @@
 	/*
 	 * process option flags
 	 */
-	while ((c = getoldopt(argc, argv,
-	    "b:cef:hmopqruts:vwxzBC:HLOPXZ014578"))
+	while (!Tflag && (c = getoldopt(argc, argv,
+	    "b:cef:hmopqruts:vwxzBC:HLOPT:XZ014578"))
 	    != -1) {
 		switch(c) {
 		case 'b':
@@ -764,6 +765,9 @@
 			 */
 			rmleadslash = 0;
 			break;
+		case 'T':
+			Tflag = 1;
+			break;
 		case 'X':
 			/*
 			 * do not pass over mount points in the file system
@@ -810,7 +814,7 @@
 		listf = stdout;
 
 	/* Traditional tar behaviour (pax wants to read filelist from stdin)
*/
-	if ((act == ARCHIVE || act == APPND) && argc == 0)
+	if ((act == ARCHIVE || act == APPND) && argc == 0 && !Tflag)
 		exit(0);
 
 	/*
@@ -834,22 +838,28 @@
 		{
 			int sawpat = 0;
 
-			while (*argv != NULL) {
-				if (strcmp(*argv, "-C") == 0) {
+			while (Tflag || *argv != NULL) {
+				if (!Tflag && strcmp(*argv, "-C") == 0) {
 					if(*++argv == NULL)
 						break;
 					chdname = *argv++;
 
 					continue;
 				} 
-				if (strcmp(*argv, "-T") == 0) {
+				if (Tflag || strcmp(*argv, "-T") == 0) {
 					FILE *fp;
 					char *str;
-
-					if (*++argv == NULL)
+					
+					if (Tflag) {
+					    Tflag = 0;
+					    str = optarg;
+					} else {
+					    if (*++argv == NULL)
 						break;
+					    str = *argv++;
+					}
 
-					if ((fp = fopen(*argv, "r")) ==
NULL) {
+					if ((fp = fopen(str, "r")) == NULL)
{
 						paxwarn(1, "Unable to open
file '%s' for read", *argv);
 						tar_usage();
 					}
@@ -863,7 +873,6 @@
 						paxwarn(1, "Problem with
file '%s'", *argv);
 						tar_usage();
 					}
-					argv++;
 
 					continue;
 				}
@@ -887,8 +896,8 @@
 				tar_usage();
 		}
 
-		while (*argv != NULL) {
-			if (strcmp(*argv, "-C") == 0) {
+		while (Tflag || *argv != NULL) {
+			if (!Tflag && strcmp(*argv, "-C") == 0) {
 				if (*++argv == NULL)
 					break;
 				if (ftree_add(*argv++, 1) < 0)
@@ -896,14 +905,20 @@
 
 				continue;
 			}
-			if (strcmp(*argv, "-T") == 0) {
+			if (Tflag || strcmp(*argv, "-T") == 0) {
 				FILE *fp;
 				char *str;
 
-				if (*++argv == NULL)
+				if (Tflag) {
+				    Tflag = 0;
+				    str = optarg;
+				} else {
+				    if (*++argv == NULL)
 					break;
+				    str = *argv++;
+				}
 
-				if ((fp = fopen(*argv, "r")) == NULL) {
+				if ((fp = fopen(str, "r")) == NULL) {
 					paxwarn(1, "Unable to open file '%s'
for read", *argv);
 					tar_usage();
 				}
@@ -916,7 +931,6 @@
 					paxwarn(1, "Problem with file '%s'",
*argv);
 					tar_usage();
 				}
-				argv++;
 
 				continue;
 			}












>Audit-Trail:
>Unformatted: