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>
This commit is contained in:
		| @@ -33,7 +33,7 @@ char* FAST_FUNC append_ext(char *filename, const char *expected_ext) | ||||
| } | ||||
|  | ||||
| int FAST_FUNC bbunpack(char **argv, | ||||
| 	IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(unpack_info_t *info), | ||||
| 	IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux), | ||||
| 	char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext), | ||||
| 	const char *expected_ext | ||||
| ) | ||||
| @@ -42,7 +42,7 @@ int FAST_FUNC bbunpack(char **argv, | ||||
| 	IF_DESKTOP(long long) int status; | ||||
| 	char *filename, *new_name; | ||||
| 	smallint exitcode = 0; | ||||
| 	unpack_info_t info; | ||||
| 	transformer_aux_data_t aux; | ||||
|  | ||||
| 	do { | ||||
| 		/* NB: new_name is *maybe* malloc'ed! */ | ||||
| @@ -98,9 +98,9 @@ int FAST_FUNC bbunpack(char **argv, | ||||
| 					"use -f to force it"); | ||||
| 		} | ||||
|  | ||||
| 		/* memset(&info, 0, sizeof(info)); */ | ||||
| 		info.mtime = 0; /* so far it has one member only */ | ||||
| 		status = unpacker(&info); | ||||
| 		init_transformer_aux_data(&aux); | ||||
| 		aux.check_signature = 1; | ||||
| 		status = unpacker(&aux); | ||||
| 		if (status < 0) | ||||
| 			exitcode = 1; | ||||
|  | ||||
| @@ -111,10 +111,10 @@ int FAST_FUNC bbunpack(char **argv, | ||||
| 			char *del = new_name; | ||||
| 			if (status >= 0) { | ||||
| 				/* TODO: restore other things? */ | ||||
| 				if (info.mtime) { | ||||
| 				if (aux.mtime != 0) { | ||||
| 					struct timeval times[2]; | ||||
|  | ||||
| 					times[1].tv_sec = times[0].tv_sec = info.mtime; | ||||
| 					times[1].tv_sec = times[0].tv_sec = aux.mtime; | ||||
| 					times[1].tv_usec = times[0].tv_usec = 0; | ||||
| 					/* Note: we closed it first. | ||||
| 					 * On some systems calling utimes | ||||
| @@ -182,16 +182,9 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext) | ||||
|  | ||||
| #if ENABLE_UNCOMPRESS | ||||
| static | ||||
| IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(unpack_info_t *info UNUSED_PARAM) | ||||
| IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux) | ||||
| { | ||||
| 	IF_DESKTOP(long long) int status = -1; | ||||
|  | ||||
| 	if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) { | ||||
| 		bb_error_msg("invalid magic"); | ||||
| 	} else { | ||||
| 		status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO); | ||||
| 	} | ||||
| 	return status; | ||||
| 	return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO); | ||||
| } | ||||
| int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||||
| int uncompress_main(int argc UNUSED_PARAM, char **argv) | ||||
| @@ -279,30 +272,30 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN | ||||
| 	return filename; | ||||
| } | ||||
| static | ||||
| IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(unpack_info_t *info) | ||||
| IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux) | ||||
| { | ||||
| 	IF_DESKTOP(long long) int status = -1; | ||||
| 	uint16_t magic2; | ||||
|  | ||||
| 	/* do the decompression, and cleanup */ | ||||
| 	if (xread_char(STDIN_FILENO) == 0x1f) { | ||||
| 		unsigned char magic2; | ||||
| //TODO: fold below into unpack_gz_stream? Then the whole level of indirection | ||||
| // unpack_FOO() -> unpack_FOO_stream can be collapsed in this module! | ||||
|  | ||||
| 		magic2 = xread_char(STDIN_FILENO); | ||||
| 		if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == 0x9d) { | ||||
| 			status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO); | ||||
| 		} else if (magic2 == 0x8b) { | ||||
| 			status = unpack_gz_stream_with_info(STDIN_FILENO, STDOUT_FILENO, info); | ||||
| 		} else { | ||||
| 			goto bad_magic; | ||||
| 		} | ||||
| 		if (status < 0) { | ||||
| 			bb_error_msg("error inflating"); | ||||
| 		} | ||||
| 	aux->check_signature = 0; /* we will check it here, not in unpack_*_stream */ | ||||
|  | ||||
| 	if (full_read(STDIN_FILENO, &magic2, 2) != 2) | ||||
| 		goto bad_magic; | ||||
| 	if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == COMPRESS_MAGIC) { | ||||
| 		status = unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO); | ||||
| 	} else if (magic2 == GZIP_MAGIC) { | ||||
| 		status = unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO); | ||||
| 	} else { | ||||
|  bad_magic: | ||||
| 		bb_error_msg("invalid magic"); | ||||
| 		/* status is still == -1 */ | ||||
| 	} | ||||
| 	if (status < 0) { | ||||
| 		bb_error_msg("error inflating"); | ||||
| 	} | ||||
| 	return status; | ||||
| } | ||||
| /* | ||||
| @@ -352,9 +345,9 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) | ||||
| //applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat)) | ||||
| #if ENABLE_BUNZIP2 | ||||
| static | ||||
| IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(unpack_info_t *info UNUSED_PARAM) | ||||
| IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux) | ||||
| { | ||||
| 	return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO); | ||||
| 	return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO); | ||||
| } | ||||
| int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||||
| int bunzip2_main(int argc UNUSED_PARAM, char **argv) | ||||
| @@ -420,9 +413,9 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv) | ||||
|  | ||||
| #if ENABLE_UNLZMA | ||||
| static | ||||
| IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(unpack_info_t *info UNUSED_PARAM) | ||||
| IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux) | ||||
| { | ||||
| 	return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO); | ||||
| 	return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO); | ||||
| } | ||||
| int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||||
| int unlzma_main(int argc UNUSED_PARAM, char **argv) | ||||
| @@ -445,18 +438,9 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv) | ||||
|  | ||||
| #if ENABLE_UNXZ | ||||
| static | ||||
| IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(unpack_info_t *info UNUSED_PARAM) | ||||
| IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux) | ||||
| { | ||||
| 	struct { | ||||
| 		uint32_t v1; | ||||
| 		uint16_t v2; | ||||
| 	} magic; | ||||
| 	xread(STDIN_FILENO, &magic, 6); | ||||
| 	if (magic.v1 != XZ_MAGIC1a || magic.v2 != XZ_MAGIC2a) { | ||||
| 		bb_error_msg("invalid magic"); | ||||
| 		return -1; | ||||
| 	} | ||||
| 	return unpack_xz_stream(STDIN_FILENO, STDOUT_FILENO); | ||||
| 	return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO); | ||||
| } | ||||
| int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||||
| int unxz_main(int argc UNUSED_PARAM, char **argv) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user