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

Suggested pax changes (tar/cpio compatibility)



I was looking at tar(pax) and found that it does not emulate the behavior
of tar completely when extracting files verbosely (tar -xvf -).
pax normally lists these files to stderr. which is the behavior of
pax on other systems (correct), however when pax is in cpio or tar
emulation mode, it also lists these files to stderr, which is different
that other versions of tar/cpio (Solaris and gnutar tested, Solaris cpio
tested).

I propose that the behavior be changed to follow the normal actions
of these programs so if tar or pax is used in any scripts would be
still be portable.

I did find and have fixed on other bug found in this code.
If cpio was extracting and the file could not be created, it would print
the line with the name, but would not print the trailing '\n'.
thus the screen would be filled with filenames joined on a line with
no space or newline.


Index: ar_subs.c
===================================================================
RCS file: /cvs/src/bin/pax/ar_subs.c,v
retrieving revision 1.13
diff -u -r1.13 ar_subs.c
--- ar_subs.c	1997/09/16 21:20:35	1.13
+++ ar_subs.c	1998/09/19 19:19:35
@@ -161,6 +161,7 @@
  *	pattern(s) (no patterns extracts all members)
  */
 
+int stdoutlistmode=0;
 #ifdef __STDC__
 void
 extract(void)
@@ -176,7 +177,13 @@
 	struct stat sb;
 	int fd;
 	time_t now;
+	FILE *outf;
 
+	if (stdoutlistmode == 0) {
+		outf = stderr;
+	} else {
+		outf = stdout;
+	}
 	arcn = &archd;
 	/*
 	 * figure out archive type; pass any format specific options to the
@@ -284,9 +291,9 @@
 
 		if (vflag) {
 			if (vflag > 1)
-				ls_list(arcn, now, stderr);
+				ls_list(arcn, now, outf);
 			else {
-				(void)fputs(arcn->name, stderr);
+				(void)fputs(arcn->name, outf);
 				vfpart = 1;
 			}
 		}
@@ -318,7 +325,7 @@
 				purg_lnk(arcn);
 
 			if (vflag && vfpart) {
-				(void)putc('\n', stderr);
+				(void)putc('\n', outf);
 				vfpart = 0;
 			}
 			continue;
@@ -330,6 +337,10 @@
 		if ((fd = file_creat(arcn)) < 0) {
 			(void)rd_skip(arcn->skip + arcn->pad);
 			purg_lnk(arcn);
+			if (vflag && vfpart) {
+				(void)putc('\n', outf);
+				vfpart = 0;
+			}
 			continue;
 		}
 		/*
@@ -339,7 +350,7 @@
 		res = (*frmt->rd_data)(arcn, fd, &cnt);
 		file_close(arcn, fd);
 		if (vflag && vfpart) {
-			(void)putc('\n', stderr);
+			(void)putc('\n', outf);
 			vfpart = 0;
 		}
 		if (!res)
Index: extern.h
===================================================================
RCS file: /cvs/src/bin/pax/extern.h,v
retrieving revision 1.14
diff -u -r1.14 extern.h
--- extern.h	1997/07/24 23:19:18	1.14
+++ extern.h	1998/09/19 19:19:35
@@ -233,6 +233,7 @@
 extern int pmode;
 extern int pids;
 extern int rmleadslash;
+extern int stdoutlistmode;
 extern int exit_val;
 extern int docrc;
 extern char *dirptr;
Index: options.c
===================================================================
RCS file: /cvs/src/bin/pax/options.c,v
retrieving revision 1.33
diff -u -r1.33 options.c
--- options.c	1998/03/31 17:14:21	1.33
+++ options.c	1998/09/19 19:19:37
@@ -810,8 +810,9 @@
 	 * process the args as they are interpreted by the operation mode
 	 */
 	switch (act) {
-	case LIST:
 	case EXTRACT:
+		stdoutlistmode=1;
+	case LIST:
 	default:
 		{
 			int sawpat = 0;
@@ -967,6 +968,7 @@
 				 * restore an archive
 				 */
 				act = EXTRACT;
+				stdoutlistmode=1;
 				break;
 			case 'k':
 				break;

Dale Rahn                                                  drahn_(_at_)_pdnt_(_dot_)_com

Visit your host, monkey.org