Write files when extracting an archive from standard input.
authorMatt Kraai <kraai@debian.org>
Thu, 20 Dec 2001 22:09:31 +0000 (22:09 -0000)
committerMatt Kraai <kraai@debian.org>
Thu, 20 Dec 2001 22:09:31 +0000 (22:09 -0000)
archival/tar.c
testsuite/tar/tar-extracts-from-standard-input [new file with mode: 0644]

index 9792f6b9d72a7b04afe25391a434404142f67986..8720144b26de28e5d32494d8c8798dd087edeca4 100644 (file)
@@ -459,7 +459,7 @@ static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
                error_msg_and_die("Cowardly refusing to create an empty archive");
 
        /* Open the tar file for writing.  */
-       if (tarName == NULL || !strcmp(tarName, "-"))
+       if (tarName == NULL)
                tbInfo.tarFd = fileno(stdout);
        else
                tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
@@ -573,14 +573,12 @@ char **list_and_not_list(char **include_list, char **exclude_list)
 int tar_main(int argc, char **argv)
 {
        enum untar_funct_e {
-               /* These are optional */
-               untar_from_file = 1,
-               untar_from_stdin = 2,
-               untar_unzip = 4,
+               /* This is optional */
+               untar_unzip = 1,
                /* Require one and only one of these */
-               untar_list = 8,
-               untar_create = 16,
-               untar_extract = 32
+               untar_list = 2,
+               untar_create = 4,
+               untar_extract = 8
        };
 
        FILE *src_stream = NULL;
@@ -649,10 +647,8 @@ int tar_main(int argc, char **argv)
                        break;
                case 'f':       // archive filename
                        if (strcmp(optarg, "-") == 0) {
-                               // Untar from stdin to stdout
-                               untar_funct |= untar_from_stdin;
+                               src_filename = NULL;
                        } else {
-                               untar_funct |= untar_from_file;
                                src_filename = xstrdup(optarg);
                        }
                        break;
@@ -694,17 +690,13 @@ int tar_main(int argc, char **argv)
                optind++;
        }
 
-       if (src_filename == NULL) {
-               extract_function |= extract_to_stdout;
-       }
-
        if (extract_function & (extract_list | extract_all_to_fs)) {
                if (dst_prefix == NULL) {
                        dst_prefix = xstrdup("./");
                }
 
                /* Setup the source of the tar data */
-               if (untar_funct & untar_from_file) {
+               if (src_filename != NULL) {
                        src_stream = xfopen(src_filename, "r");
                } else {
                        src_stream = stdin;
diff --git a/testsuite/tar/tar-extracts-from-standard-input b/testsuite/tar/tar-extracts-from-standard-input
new file mode 100644 (file)
index 0000000..a30e9f0
--- /dev/null
@@ -0,0 +1,5 @@
+touch foo
+tar cf foo.tar foo
+rm foo
+cat foo.tar | busybox tar x
+test -f foo