From 9cd29befcaf71477e2673a2e530354e3605f8c63 Mon Sep 17 00:00:00 2001 From: Dave Vasilevsky Date: Mon, 11 Oct 2010 00:05:36 -0400 Subject: [PATCH] Allow writing non-tar archives --- write.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/write.c b/write.c index 857fa7b..bf7dfbd 100644 --- a/write.c +++ b/write.c @@ -3,6 +3,7 @@ #include #include +#include #pragma mark TYPES @@ -26,6 +27,8 @@ struct io_block_t { #define DEBUG 0 +static bool gTar = true; + static size_t gNumEncodeThreads = 0; static pthread_t *gEncodeThreads = NULL; static pthread_t gReadThread; @@ -79,6 +82,21 @@ static void write_file_index_buf(lzma_action action); int main(int argc, char **argv) { debug("launch"); + + int ch; + while ((ch = getopt(argc, argv, "t")) != -1) { + switch (ch) { + case 't': + gTar = false; + break; + default: + die("Unknown option"); + } + } + argc -= optind - 1; + argv += optind - 1; + + if (argc != 3) die("Need two arguments"); if (!(gInFile = fopen(argv[1], "r"))) @@ -137,8 +155,10 @@ int main(int argc, char **argv) { } // file index - write_file_index(); - free_file_index(); + if (gTar) { + write_file_index(); + free_file_index(); + } // post-block cleanup: index, footer encode_index(); @@ -167,7 +187,9 @@ static void *read_thread(void *data) { struct archive *ar = archive_read_new(); archive_read_support_compression_none(ar); - archive_read_support_format_tar(ar); + if (gTar) + archive_read_support_format_tar(ar); + archive_read_support_format_raw(ar); archive_read_open(ar, NULL, tar_ok, tar_read, tar_ok); struct archive_entry *entry; while (true) { @@ -181,12 +203,17 @@ static void *read_thread(void *data) { die("Error reading archive entry"); } - add_file(archive_read_header_position(ar), - archive_entry_pathname(entry)); - } + if (archive_format(ar) == ARCHIVE_FORMAT_RAW) + gTar = false; + if (gTar) { + add_file(archive_read_header_position(ar), + archive_entry_pathname(entry)); + } + } archive_read_finish(ar); fclose(gInFile); - add_file(gTotalRead, NULL); + if (gTar) + add_file(gTotalRead, NULL); // write last block, if necessary if (gReadBlock) {