diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-19 11:26:28 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-19 11:26:28 +0000 |
commit | 431a7c9c53b69a7416091721da673bcff7c91a02 (patch) | |
tree | 03cbe0e15af01d82b05138f0db41d44179262a3f /archival/tar.c | |
parent | a37e7134f76b7661b86bb9cc926f28f81b1e1109 (diff) | |
download | busybox-w32-431a7c9c53b69a7416091721da673bcff7c91a02.tar.gz busybox-w32-431a7c9c53b69a7416091721da673bcff7c91a02.tar.bz2 busybox-w32-431a7c9c53b69a7416091721da673bcff7c91a02.zip |
tar: optional autodetection of gz/bz2 compressed tarballs.
+130 bytes. Closes bug 992.
Diffstat (limited to 'archival/tar.c')
-rw-r--r-- | archival/tar.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/archival/tar.c b/archival/tar.c index 4ec454b88..e790f28ea 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -33,8 +33,17 @@ | |||
33 | #define FNM_LEADING_DIR 0 | 33 | #define FNM_LEADING_DIR 0 |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | |||
36 | #define block_buf bb_common_bufsiz1 | 37 | #define block_buf bb_common_bufsiz1 |
37 | 38 | ||
39 | |||
40 | #if !ENABLE_FEATURE_TAR_GZIP && !ENABLE_FEATURE_TAR_BZIP2 | ||
41 | /* Do not pass gzip flag to writeTarFile() */ | ||
42 | #define writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude, gzip) \ | ||
43 | writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude) | ||
44 | #endif | ||
45 | |||
46 | |||
38 | #if ENABLE_FEATURE_TAR_CREATE | 47 | #if ENABLE_FEATURE_TAR_CREATE |
39 | 48 | ||
40 | /* Tar file constants */ | 49 | /* Tar file constants */ |
@@ -514,18 +523,23 @@ static int writeTarFile(const int tar_fd, const int verboseFlag, | |||
514 | if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0) | 523 | if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0) |
515 | bb_perror_msg_and_die("cannot stat tar file"); | 524 | bb_perror_msg_and_die("cannot stat tar file"); |
516 | 525 | ||
517 | if ((ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2) && gzip) { | 526 | #if ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2 |
518 | // On Linux, vfork never unpauses parent early, although standard | 527 | if (gzip) { |
519 | // allows for that. Do we want to waste bytes checking for it? | 528 | #if ENABLE_FEATURE_TAR_GZIP && ENABLE_FEATURE_TAR_BZIP2 |
529 | const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2"; | ||
530 | #elif ENABLE_FEATURE_TAR_GZIP | ||
531 | const char *zip_exec = "gzip"; | ||
532 | #else /* only ENABLE_FEATURE_TAR_BZIP2 */ | ||
533 | const char *zip_exec = "bzip2"; | ||
534 | #endif | ||
535 | // On Linux, vfork never unpauses parent early, although standard | ||
536 | // allows for that. Do we want to waste bytes checking for it? | ||
520 | #define WAIT_FOR_CHILD 0 | 537 | #define WAIT_FOR_CHILD 0 |
521 | |||
522 | volatile int vfork_exec_errno = 0; | 538 | volatile int vfork_exec_errno = 0; |
523 | #if WAIT_FOR_CHILD | 539 | #if WAIT_FOR_CHILD |
524 | struct fd_pair gzipStatusPipe; | 540 | struct fd_pair gzipStatusPipe; |
525 | #endif | 541 | #endif |
526 | struct fd_pair gzipDataPipe; | 542 | struct fd_pair gzipDataPipe; |
527 | const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2"; | ||
528 | |||
529 | xpiped_pair(gzipDataPipe); | 543 | xpiped_pair(gzipDataPipe); |
530 | #if WAIT_FOR_CHILD | 544 | #if WAIT_FOR_CHILD |
531 | xpiped_pair(gzipStatusPipe); | 545 | xpiped_pair(gzipStatusPipe); |
@@ -584,6 +598,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag, | |||
584 | bb_perror_msg_and_die("cannot exec %s", zip_exec); | 598 | bb_perror_msg_and_die("cannot exec %s", zip_exec); |
585 | } | 599 | } |
586 | } | 600 | } |
601 | #endif | ||
587 | 602 | ||
588 | tbInfo.excludeList = exclude; | 603 | tbInfo.excludeList = exclude; |
589 | 604 | ||
@@ -934,11 +949,13 @@ int tar_main(int argc, char **argv) | |||
934 | 949 | ||
935 | /* create an archive */ | 950 | /* create an archive */ |
936 | if (opt & OPT_CREATE) { | 951 | if (opt & OPT_CREATE) { |
952 | #if ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2 | ||
937 | int zipMode = 0; | 953 | int zipMode = 0; |
938 | if (ENABLE_FEATURE_TAR_GZIP && get_header_ptr == get_header_tar_gz) | 954 | if (ENABLE_FEATURE_TAR_GZIP && (opt & OPT_GZIP)) |
939 | zipMode = 1; | 955 | zipMode = 1; |
940 | if (ENABLE_FEATURE_TAR_BZIP2 && get_header_ptr == get_header_tar_bz2) | 956 | if (ENABLE_FEATURE_TAR_BZIP2 && (opt & OPT_BZIP2)) |
941 | zipMode = 2; | 957 | zipMode = 2; |
958 | #endif | ||
942 | /* NB: writeTarFile() closes tar_handle->src_fd */ | 959 | /* NB: writeTarFile() closes tar_handle->src_fd */ |
943 | return writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE, | 960 | return writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE, |
944 | tar_handle->accept, | 961 | tar_handle->accept, |
@@ -946,7 +963,7 @@ int tar_main(int argc, char **argv) | |||
946 | } | 963 | } |
947 | 964 | ||
948 | while (get_header_ptr(tar_handle) == EXIT_SUCCESS) | 965 | while (get_header_ptr(tar_handle) == EXIT_SUCCESS) |
949 | /* nothing */; | 966 | continue; |
950 | 967 | ||
951 | /* Check that every file that should have been extracted was */ | 968 | /* Check that every file that should have been extracted was */ |
952 | while (tar_handle->accept) { | 969 | while (tar_handle->accept) { |