aboutsummaryrefslogtreecommitdiff
path: root/archival/tar.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-03-06 16:27:48 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2012-03-06 16:27:48 +0100
commit8a6a2f9c9c214b94bd945acd97ac8b28c25e194e (patch)
tree08b9a2af482bb50a7e369c01f9e9083680543fd4 /archival/tar.c
parent774bce8e8ba1e424c953e8f13aee8f0778c8a911 (diff)
downloadbusybox-w32-8a6a2f9c9c214b94bd945acd97ac8b28c25e194e.tar.gz
busybox-w32-8a6a2f9c9c214b94bd945acd97ac8b28c25e194e.tar.bz2
busybox-w32-8a6a2f9c9c214b94bd945acd97ac8b28c25e194e.zip
update seamless uncompression code
This change makes "tar tf hello_world.txz" work without adding special-casing for ".txz" extension. It also removes ever-growing magic checking code in rpm2cpio and get_header_tar - we reuse one which lives in setup_unzip_on_fd. function old new delta unpack_gz_stream 7 566 +559 check_signature16 - 70 +70 setup_unzip_on_fd 99 142 +43 handle_SIGCHLD - 41 +41 unpack_bz2_stream 342 376 +34 unzip_main 2352 2385 +33 bbunpack 503 533 +30 open_transformer 74 102 +28 unpack_Z_stream 1278 1304 +26 unpack_gunzip 101 123 +22 init_transformer_aux_data - 18 +18 unpack_xz_stream 2388 2402 +14 open_zipped 131 141 +10 rpm_main 1358 1363 +5 get_header_tar_lzma 52 57 +5 get_header_tar_bz2 52 57 +5 unpack_lzma_stream 2698 2702 +4 hash_find 234 233 -1 get_header_tar 1759 1733 -26 get_header_tar_gz 92 57 -35 unpack_uncompress 51 12 -39 rpm2cpio_main 201 147 -54 unpack_unxz 67 12 -55 unpack_bz2_stream_prime 55 - -55 get_header_tar_Z 86 - -86 unpack_gz_stream_with_info 539 - -539 ------------------------------------------------------------------------------ (add/remove: 3/3 grow/shrink: 14/6 up/down: 947/-890) Total: 57 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival/tar.c')
-rw-r--r--archival/tar.c71
1 files changed, 31 insertions, 40 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 766b79b2b..af38ac59f 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -690,31 +690,6 @@ static llist_t *append_file_list_to_list(llist_t *list)
690# define append_file_list_to_list(x) 0 690# define append_file_list_to_list(x) 0
691#endif 691#endif
692 692
693#if ENABLE_FEATURE_SEAMLESS_Z
694static char FAST_FUNC get_header_tar_Z(archive_handle_t *archive_handle)
695{
696 /* Can't lseek over pipes */
697 archive_handle->seek = seek_by_read;
698
699 /* do the decompression, and cleanup */
700 if (xread_char(archive_handle->src_fd) != 0x1f
701 || xread_char(archive_handle->src_fd) != 0x9d
702 ) {
703 bb_error_msg_and_die("invalid magic");
704 }
705
706 open_transformer(archive_handle->src_fd, unpack_Z_stream, "uncompress");
707 archive_handle->offset = 0;
708 while (get_header_tar(archive_handle) == EXIT_SUCCESS)
709 continue;
710
711 /* Can only do one file at a time */
712 return EXIT_FAILURE;
713}
714#else
715# define get_header_tar_Z NULL
716#endif
717
718#ifdef CHECK_FOR_CHILD_EXITCODE 693#ifdef CHECK_FOR_CHILD_EXITCODE
719/* Looks like it isn't needed - tar detects malformed (truncated) 694/* Looks like it isn't needed - tar detects malformed (truncated)
720 * archive if e.g. bunzip2 fails */ 695 * archive if e.g. bunzip2 fails */
@@ -843,6 +818,8 @@ enum {
843 OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner 818 OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
844 OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions 819 OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
845 OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite 820 OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
821
822 OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_COMPRESS),
846}; 823};
847#if ENABLE_FEATURE_TAR_LONG_OPTIONS 824#if ENABLE_FEATURE_TAR_LONG_OPTIONS
848static const char tar_longopts[] ALIGN1 = 825static const char tar_longopts[] ALIGN1 =
@@ -901,7 +878,6 @@ static const char tar_longopts[] ALIGN1 =
901int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 878int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
902int tar_main(int argc UNUSED_PARAM, char **argv) 879int tar_main(int argc UNUSED_PARAM, char **argv)
903{ 880{
904 char FAST_FUNC (*get_header_ptr)(archive_handle_t *) = get_header_tar;
905 archive_handle_t *tar_handle; 881 archive_handle_t *tar_handle;
906 char *base_dir = NULL; 882 char *base_dir = NULL;
907 const char *tar_filename = "-"; 883 const char *tar_filename = "-";
@@ -1017,18 +993,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1017 tar_handle->ah_flags |= ARCHIVE_O_TRUNC; 993 tar_handle->ah_flags |= ARCHIVE_O_TRUNC;
1018 } 994 }
1019 995
1020 if (opt & OPT_GZIP)
1021 get_header_ptr = get_header_tar_gz;
1022
1023 if (opt & OPT_BZIP2)
1024 get_header_ptr = get_header_tar_bz2;
1025
1026 if (opt & OPT_LZMA)
1027 get_header_ptr = get_header_tar_lzma;
1028
1029 if (opt & OPT_COMPRESS)
1030 get_header_ptr = get_header_tar_Z;
1031
1032 if (opt & OPT_NOPRESERVE_TIME) 996 if (opt & OPT_NOPRESERVE_TIME)
1033 tar_handle->ah_flags &= ~ARCHIVE_RESTORE_DATE; 997 tar_handle->ah_flags &= ~ARCHIVE_RESTORE_DATE;
1034 998
@@ -1081,7 +1045,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1081 } else { 1045 } else {
1082 if (ENABLE_FEATURE_TAR_AUTODETECT 1046 if (ENABLE_FEATURE_TAR_AUTODETECT
1083 && flags == O_RDONLY 1047 && flags == O_RDONLY
1084 && get_header_ptr == get_header_tar 1048 && !(opt & OPT_ANY_COMPRESS)
1085 ) { 1049 ) {
1086 tar_handle->src_fd = open_zipped(tar_filename); 1050 tar_handle->src_fd = open_zipped(tar_filename);
1087 if (tar_handle->src_fd < 0) 1051 if (tar_handle->src_fd < 0)
@@ -1115,7 +1079,30 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1115 tar_handle->reject, zipMode); 1079 tar_handle->reject, zipMode);
1116 } 1080 }
1117 1081
1118 while (get_header_ptr(tar_handle) == EXIT_SUCCESS) 1082 if (opt & OPT_ANY_COMPRESS) {
1083 USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
1084 USE_FOR_NOMMU(const char *xformer_prog;)
1085
1086 if (opt & OPT_COMPRESS)
1087 USE_FOR_MMU(xformer = unpack_Z_stream;)
1088 USE_FOR_NOMMU(xformer_prog = "uncompress";)
1089 if (opt & OPT_GZIP)
1090 USE_FOR_MMU(xformer = unpack_gz_stream;)
1091 USE_FOR_NOMMU(xformer_prog = "gunzip";)
1092 if (opt & OPT_BZIP2)
1093 USE_FOR_MMU(xformer = unpack_bz2_stream;)
1094 USE_FOR_NOMMU(xformer_prog = "bunzip2";)
1095 if (opt & OPT_LZMA)
1096 USE_FOR_MMU(xformer = unpack_lzma_stream;)
1097 USE_FOR_NOMMU(xformer_prog = "unlzma";)
1098
1099 open_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
1100 /* Can't lseek over pipes */
1101 tar_handle->seek = seek_by_read;
1102 /*tar_handle->offset = 0; - already is */
1103 }
1104
1105 while (get_header_tar(tar_handle) == EXIT_SUCCESS)
1119 continue; 1106 continue;
1120 1107
1121 /* Check that every file that should have been extracted was */ 1108 /* Check that every file that should have been extracted was */
@@ -1131,5 +1118,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1131 if (ENABLE_FEATURE_CLEAN_UP /* && tar_handle->src_fd != STDIN_FILENO */) 1118 if (ENABLE_FEATURE_CLEAN_UP /* && tar_handle->src_fd != STDIN_FILENO */)
1132 close(tar_handle->src_fd); 1119 close(tar_handle->src_fd);
1133 1120
1121#ifdef CHECK_FOR_CHILD_EXITCODE
1122 return bb_got_signal;
1123#else
1134 return EXIT_SUCCESS; 1124 return EXIT_SUCCESS;
1125#endif
1135} 1126}