From 2c5c33120a279700b38d3edc7aec01248fdf9a66 Mon Sep 17 00:00:00 2001 From: Dave Vasilevsky Date: Wed, 13 Oct 2010 23:36:48 -0400 Subject: [PATCH] Don't read index unless necessary --- common.c | 9 +++++---- list.c | 2 +- pixz.h | 2 +- pread.c | 11 ++++++----- read.c | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/common.c b/common.c index 90431dd..e0011ed 100644 --- a/common.c +++ b/common.c @@ -140,10 +140,11 @@ lzma_vli find_file_index(void **bdatap) { return ret; } -lzma_vli read_file_index(void) { - void *bdata; - lzma_vli offset = find_file_index(&bdata); - if (!bdata) +lzma_vli read_file_index(lzma_vli offset) { + void *bdata = NULL; + if (!offset) + offset = find_file_index(&bdata); + if (!offset) return 0; while (true) { diff --git a/list.c b/list.c index 0ce734b..fbe832b 100644 --- a/list.c +++ b/list.c @@ -40,7 +40,7 @@ int main(int argc, char **argv) { (uintmax_t)iter.block.uncompressed_size); } - if (tar && read_file_index()) { + if (tar && read_file_index(0)) { printf("\n"); dump_file_index(stdout); free_file_index(); diff --git a/pixz.h b/pixz.h index 6467ce4..4c52792 100644 --- a/pixz.h +++ b/pixz.h @@ -57,7 +57,7 @@ bool is_multi_header(const char *name); void decode_index(void); lzma_vli find_file_index(void **bdatap); -lzma_vli read_file_index(void); +lzma_vli read_file_index(lzma_vli offset); void dump_file_index(FILE *out); void free_file_index(void); diff --git a/pread.c b/pread.c index b7a6932..7d6466d 100644 --- a/pread.c +++ b/pread.c @@ -6,8 +6,8 @@ #include /* TODO - * - Don't read index unless necessary? * - Check sizes of files vs index + * - Test against "normal" xz, txz files */ #define DEBUG 0 @@ -94,8 +94,9 @@ int main(int argc, char **argv) { } } - // TODO: ONly read index if necessary? - gFileIndexOffset = read_file_index(); + decode_index(); + if (verify) + gFileIndexOffset = read_file_index(0); wanted_files(argc - optind, argv + optind); #if DEBUG for (wanted_t *w = gWantedFiles; w; w = w->next) @@ -122,8 +123,8 @@ int main(int argc, char **argv) { die("Error reading archive entry"); } const char *path = archive_entry_pathname(entry); - if (is_multi_header(path)) - continue; +// if (is_multi_header(path)) +// continue; size_t size = archive_entry_size(entry); if (!w) diff --git a/read.c b/read.c index a30e10c..c12c0bd 100644 --- a/read.c +++ b/read.c @@ -16,7 +16,7 @@ int main(int argc, char **argv) { die("Can't open input file"); char *target = argv[2]; - if (!read_file_index()) + if (!read_file_index(0)) die("File has no index"); extract_file(target);