Move seamless .Z support into unpack_gz_stream
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 6 Mar 2012 15:32:06 +0000 (16:32 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 6 Mar 2012 15:32:06 +0000 (16:32 +0100)
unpack_gz_stream                                     566     643     +77
unpack_gunzip                                        123      12    -111

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/Config.src
archival/bbunzip.c
archival/libarchive/decompress_gunzip.c

index 885cb5bcca7351ef84eae949d5e1bcf7faa8374e..ae1afc5942a71229f378d4794294d93ff873edbe 100644 (file)
@@ -32,10 +32,10 @@ config FEATURE_SEAMLESS_GZ
          Make tar, rpm, modprobe etc understand .gz data.
 
 config FEATURE_SEAMLESS_Z
-       bool "Make tar and gunzip understand .Z data"
+       bool "tar, rpm, modprobe etc understand .Z data"
        default n
        help
-         Make tar and gunzip understand .Z data.
+         Make tar, rpm, modprobe etc understand .Z data.
 
 config AR
        bool "ar"
index 1bc04ed334f2f19b176f9dcecab5389e14d97a99..94d8a81c94d4a68bf4a2ba7c3e31099729c8423a 100644 (file)
@@ -274,29 +274,7 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
 static
 IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
 {
-       IF_DESKTOP(long long) int status = -1;
-       uint16_t 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!
-
-       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;
+       return unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
 }
 /*
  * Linux kernel build uses gzip -d -n. We accept and ignore it.
index f1c9a79e51399e8c454cdcfb3d94eb643c875ec1..66152a85397f6b6f71278ca98d6e02929ef3b99e 100644 (file)
@@ -1188,8 +1188,26 @@ unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
        IF_DESKTOP(long long) int total, n;
        DECLARE_STATE;
 
+#if !ENABLE_FEATURE_SEAMLESS_Z
        if (check_signature16(aux, src_fd, GZIP_MAGIC))
                return -1;
+#else
+       if (aux && aux->check_signature) {
+               uint16_t magic2;
+
+               if (full_read(STDIN_FILENO, &magic2, 2) != 2) {
+ bad_magic:
+                       bb_error_msg("invalid magic");
+                       return -1;
+               }
+               if (magic2 == COMPRESS_MAGIC) {
+                       aux->check_signature = 0;
+                       return unpack_Z_stream(aux, src_fd, dst_fd);
+               }
+               if (magic2 != GZIP_MAGIC)
+                       goto bad_magic;
+       }
+#endif
 
        total = 0;