Subject: bin/1712: tar xOf extracts to stdout, but still creates empty directories
To: None <gnats-bugs@gnats.netbsd.org>
From: None <Mark_Weaver@brown.edu>
List: netbsd-bugs
Date: 11/01/1995 11:49:50
>Number: 1712
>Category: bin
>Synopsis: tar xOf extracts to stdout, but still creates empty directories
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: mhw
>Arrival-Date: Wed Nov 1 11:50:01 1995
>Last-Modified:
>Originator: Mark Weaver
>Organization:
Brown University Department of Computer Science
>Release: NetBSD-current 9/30/95
>Environment:
NetBSD peace.netspace.org 1.0A NetBSD 1.0A (WEAVER) #3: Sat Sep 30 23:39:30 EDT 1995 mhw@cis-ts1-slip6.cis.brown.edu:/usr/src/sys/arch/i386/compile/WEAVER i386
>Description:
The -O option to tar causes plain files to be printed to stdout
instead of extracted to disk, and is useful for grepping tar files for
content, among other things. However, directories (and other
non-plain files) are still extracted to disk. This causes an empty
hierarchy to be created in most cases, which is (IMHO) undesirable.
>How-To-Repeat:
mhw ~ % mkdir tst
mhw ~ % cat > tst/a
hello world
mhw ~ % tar cvf tst.tar tst
tst/
tst/a
mhw ~ % rm -rf tst
mhw ~ % tar xOf tst.tar
hello world
mhw ~ % ls -la tst
total 3
drwxr-xr-x 2 mhw users 512 Nov 1 11:47 ./
drwxr-xr-x 21 mhw users 2048 Nov 1 11:47 ../
>Fix:
diff -u src/gnu/usr.bin/tar/extract.c.mhw1 src/gnu/usr.bin/tar/extract.c
--- src/gnu/usr.bin/tar/extract.c.mhw1 Tue Apr 25 06:06:20 1995
+++ src/gnu/usr.bin/tar/extract.c Thu Oct 5 19:53:25 1995
@@ -568,6 +568,8 @@
case LF_LINK:
again_link:
+ if (f_exstdout)
+ break;
{
struct stat st1, st2;
@@ -600,6 +602,8 @@
#ifdef S_ISLNK
case LF_SYMLINK:
again_symlink:
+ if (f_exstdout)
+ break;
if (f_unlink && !f_keep) {
if (unlink(skipcrud + current_file_name) == -1)
if (errno != ENOENT)
@@ -631,6 +635,8 @@
#endif
#if defined(S_IFCHR) || defined(S_IFBLK)
make_node:
+ if (f_exstdout)
+ break;
if (f_unlink && !f_keep) {
if (unlink(skipcrud + current_file_name) == -1)
if (errno != ENOENT)
@@ -655,6 +661,8 @@
/* If local system doesn't support FIFOs, use default case */
case LF_FIFO:
make_fifo:
+ if (f_exstdout)
+ break;
if (f_unlink && !f_keep) {
if (unlink(skipcrud + current_file_name) == -1)
if (errno != ENOENT)
@@ -679,6 +687,8 @@
case LF_DUMPDIR:
namelen = strlen (current_file_name + skipcrud) - 1;
really_dir:
+ if (f_exstdout)
+ break;
/* Check for trailing /, and zap as many as we find. */
while (namelen
&& current_file_name[skipcrud + namelen] == '/')
@@ -771,14 +781,13 @@
break;
case LF_VOLHDR:
- if (f_verbose)
- {
+ if (!f_exstdout && f_verbose)
printf ("Reading %s\n", current_file_name);
- }
break;
case LF_NAMES:
- extract_mangle (head);
+ if (!f_exstdout)
+ extract_mangle (head);
break;
case LF_MULTIVOL:
>Audit-Trail:
>Unformatted: