aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2001-12-20 22:09:31 +0000
committerMatt Kraai <kraai@debian.org>2001-12-20 22:09:31 +0000
commit2b1effdbbccf8f16ae3fed93d3178759a44d33d9 (patch)
tree53e02a8ad30b981e748925c8943ed3f52451e0c6
parentc5b5cab37d37a6dafa3c1e6b97401aca6e071b03 (diff)
downloadbusybox-w32-2b1effdbbccf8f16ae3fed93d3178759a44d33d9.tar.gz
busybox-w32-2b1effdbbccf8f16ae3fed93d3178759a44d33d9.tar.bz2
busybox-w32-2b1effdbbccf8f16ae3fed93d3178759a44d33d9.zip
Write files when extracting an archive from standard input.
-rw-r--r--archival/tar.c24
-rw-r--r--testsuite/tar/tar-extracts-from-standard-input5
2 files changed, 13 insertions, 16 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 9792f6b9d..8720144b2 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -459,7 +459,7 @@ static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
459 error_msg_and_die("Cowardly refusing to create an empty archive"); 459 error_msg_and_die("Cowardly refusing to create an empty archive");
460 460
461 /* Open the tar file for writing. */ 461 /* Open the tar file for writing. */
462 if (tarName == NULL || !strcmp(tarName, "-")) 462 if (tarName == NULL)
463 tbInfo.tarFd = fileno(stdout); 463 tbInfo.tarFd = fileno(stdout);
464 else 464 else
465 tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644); 465 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)
573int tar_main(int argc, char **argv) 573int tar_main(int argc, char **argv)
574{ 574{
575 enum untar_funct_e { 575 enum untar_funct_e {
576 /* These are optional */ 576 /* This is optional */
577 untar_from_file = 1, 577 untar_unzip = 1,
578 untar_from_stdin = 2,
579 untar_unzip = 4,
580 /* Require one and only one of these */ 578 /* Require one and only one of these */
581 untar_list = 8, 579 untar_list = 2,
582 untar_create = 16, 580 untar_create = 4,
583 untar_extract = 32 581 untar_extract = 8
584 }; 582 };
585 583
586 FILE *src_stream = NULL; 584 FILE *src_stream = NULL;
@@ -649,10 +647,8 @@ int tar_main(int argc, char **argv)
649 break; 647 break;
650 case 'f': // archive filename 648 case 'f': // archive filename
651 if (strcmp(optarg, "-") == 0) { 649 if (strcmp(optarg, "-") == 0) {
652 // Untar from stdin to stdout 650 src_filename = NULL;
653 untar_funct |= untar_from_stdin;
654 } else { 651 } else {
655 untar_funct |= untar_from_file;
656 src_filename = xstrdup(optarg); 652 src_filename = xstrdup(optarg);
657 } 653 }
658 break; 654 break;
@@ -694,17 +690,13 @@ int tar_main(int argc, char **argv)
694 optind++; 690 optind++;
695 } 691 }
696 692
697 if (src_filename == NULL) {
698 extract_function |= extract_to_stdout;
699 }
700
701 if (extract_function & (extract_list | extract_all_to_fs)) { 693 if (extract_function & (extract_list | extract_all_to_fs)) {
702 if (dst_prefix == NULL) { 694 if (dst_prefix == NULL) {
703 dst_prefix = xstrdup("./"); 695 dst_prefix = xstrdup("./");
704 } 696 }
705 697
706 /* Setup the source of the tar data */ 698 /* Setup the source of the tar data */
707 if (untar_funct & untar_from_file) { 699 if (src_filename != NULL) {
708 src_stream = xfopen(src_filename, "r"); 700 src_stream = xfopen(src_filename, "r");
709 } else { 701 } else {
710 src_stream = stdin; 702 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
index 000000000..a30e9f0b9
--- /dev/null
+++ b/testsuite/tar/tar-extracts-from-standard-input
@@ -0,0 +1,5 @@
1touch foo
2tar cf foo.tar foo
3rm foo
4cat foo.tar | busybox tar x
5test -f foo