libarchive: add capability to unpack to mem.buffer
[oweals/busybox.git] / archival / tar.c
index 3877ea4db83d35ff397749b911f2c84bcb9234d8..5bd473aac60f9ed8423912079d353f1a7bd2696e 100644 (file)
@@ -1137,7 +1137,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
                         && flags == O_RDONLY
                         && !(opt & OPT_ANY_COMPRESS)
                        ) {
-                               tar_handle->src_fd = open_zipped(tar_filename);
+                               tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
                                if (tar_handle->src_fd < 0)
                                        bb_perror_msg_and_die("can't open '%s'", tar_filename);
                        } else {
@@ -1171,7 +1171,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
        }
 
        if (opt & OPT_ANY_COMPRESS) {
-               USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
+               USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);)
                USE_FOR_NOMMU(const char *xformer_prog;)
 
                if (opt & OPT_COMPRESS)
@@ -1190,14 +1190,20 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
                        USE_FOR_MMU(xformer = unpack_xz_stream;)
                        USE_FOR_NOMMU(xformer_prog = "unxz";)
 
-               open_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
+               fork_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
                /* Can't lseek over pipes */
                tar_handle->seek = seek_by_read;
                /*tar_handle->offset = 0; - already is */
        }
 
+       /* Zero processed headers (== empty file) is not a valid tarball.
+        * We (ab)use bb_got_signal as exitcode here,
+        * because check_errors_in_children() uses _it_ as error indicator.
+        */
+       bb_got_signal = EXIT_FAILURE;
+
        while (get_header_tar(tar_handle) == EXIT_SUCCESS)
-               continue;
+               bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */
 
        /* Check that every file that should have been extracted was */
        while (tar_handle->accept) {
@@ -1213,8 +1219,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
                close(tar_handle->src_fd);
 
        if (SEAMLESS_COMPRESSION || OPT_COMPRESS) {
+               /* Set bb_got_signal to 1 if a child died with !0 exitcode */
                check_errors_in_children(0);
-               return bb_got_signal;
        }
-       return EXIT_SUCCESS;
+
+       return bb_got_signal;
 }