|
|
@ -7,6 +7,20 @@
|
|
|
|
* - verify file-index matches archive contents
|
|
|
|
* - verify file-index matches archive contents
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct wanted_t wanted_t;
|
|
|
|
|
|
|
|
struct wanted_t {
|
|
|
|
|
|
|
|
wanted_t *next;
|
|
|
|
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
size_t offset;
|
|
|
|
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static wanted_t *gWantedFiles = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void wanted_files(size_t count, char **specs);
|
|
|
|
|
|
|
|
static void wanted_free(wanted_t *w);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
typedef struct {
|
|
|
|
uint8_t *input, *output;
|
|
|
|
uint8_t *input, *output;
|
|
|
|
size_t insize, outsize;
|
|
|
|
size_t insize, outsize;
|
|
|
@ -25,8 +39,6 @@ static lzma_vli gFileIndexOffset = 0;
|
|
|
|
static size_t gBlockInSize = 0, gBlockOutSize = 0;
|
|
|
|
static size_t gBlockInSize = 0, gBlockOutSize = 0;
|
|
|
|
|
|
|
|
|
|
|
|
static void set_block_sizes(void);
|
|
|
|
static void set_block_sizes(void);
|
|
|
|
static void setup_specs(void);
|
|
|
|
|
|
|
|
static bool want_file(const char *name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int main(int argc, char **argv) {
|
|
|
@ -47,21 +59,15 @@ int main(int argc, char **argv) {
|
|
|
|
die("Unknown option");
|
|
|
|
die("Unknown option");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gFileSpecs = argv + optind;
|
|
|
|
|
|
|
|
gFileSpecEnd = gFileSpecs + argc - optind;
|
|
|
|
|
|
|
|
setup_specs();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set up file index
|
|
|
|
// Set up file index
|
|
|
|
gFileIndexOffset = read_file_index();
|
|
|
|
gFileIndexOffset = read_file_index();
|
|
|
|
set_block_sizes();
|
|
|
|
wanted_files(argc - optind, argv + optind);
|
|
|
|
for (file_index_t *fi = gFileIndex; fi; fi = fi->next) {
|
|
|
|
for (wanted_t *w = gWantedFiles; w; w = w->next)
|
|
|
|
if (!fi->name)
|
|
|
|
printf("want: %s\n", w->name);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (want_file(fi->name))
|
|
|
|
|
|
|
|
printf("want: %s\n", fi->name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set_block_sizes();
|
|
|
|
pipeline_create(block_create, block_free, read_thread, decode_thread);
|
|
|
|
pipeline_create(block_create, block_free, read_thread, decode_thread);
|
|
|
|
pipeline_item_t *pi;
|
|
|
|
pipeline_item_t *pi;
|
|
|
|
while ((pi = pipeline_merged())) {
|
|
|
|
while ((pi = pipeline_merged())) {
|
|
|
@ -71,6 +77,7 @@ int main(int argc, char **argv) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pipeline_destroy();
|
|
|
|
pipeline_destroy();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wanted_free(gWantedFiles);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -112,23 +119,26 @@ static void read_thread(void) {
|
|
|
|
lzma_index_iter iter;
|
|
|
|
lzma_index_iter iter;
|
|
|
|
lzma_index_iter_init(&iter, gIndex);
|
|
|
|
lzma_index_iter_init(&iter, gIndex);
|
|
|
|
while (!lzma_index_iter_next(&iter, LZMA_INDEX_ITER_BLOCK)) {
|
|
|
|
while (!lzma_index_iter_next(&iter, LZMA_INDEX_ITER_BLOCK)) {
|
|
|
|
size_t boffset = iter.block.compressed_file_offset;
|
|
|
|
// Don't decode the file-index
|
|
|
|
if (boffset == gFileIndexOffset)
|
|
|
|
size_t boffset = iter.block.compressed_file_offset,
|
|
|
|
|
|
|
|
bsize = iter.block.total_size;
|
|
|
|
|
|
|
|
if (gFileIndexOffset && boffset == gFileIndexOffset)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get a block to work with
|
|
|
|
pipeline_item_t *pi;
|
|
|
|
pipeline_item_t *pi;
|
|
|
|
queue_pop(gPipelineStartQ, (void**)&pi);
|
|
|
|
queue_pop(gPipelineStartQ, (void**)&pi);
|
|
|
|
io_block_t *ib = (io_block_t*)(pi->data);
|
|
|
|
io_block_t *ib = (io_block_t*)(pi->data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Seek if needed, and get the data
|
|
|
|
if (offset != boffset) {
|
|
|
|
if (offset != boffset) {
|
|
|
|
fseeko(gInFile, boffset, SEEK_SET);
|
|
|
|
fseeko(gInFile, boffset, SEEK_SET);
|
|
|
|
offset = boffset;
|
|
|
|
offset = boffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t bsize = iter.block.total_size;
|
|
|
|
|
|
|
|
ib->insize = fread(ib->input, 1, bsize, gInFile);
|
|
|
|
ib->insize = fread(ib->input, 1, bsize, gInFile);
|
|
|
|
if (ib->insize < bsize)
|
|
|
|
if (ib->insize < bsize)
|
|
|
|
die("Error reading block contents");
|
|
|
|
die("Error reading block contents");
|
|
|
|
|
|
|
|
offset += bsize;
|
|
|
|
|
|
|
|
|
|
|
|
pipeline_split(pi);
|
|
|
|
pipeline_split(pi);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -136,32 +146,56 @@ static void read_thread(void) {
|
|
|
|
pipeline_stop();
|
|
|
|
pipeline_stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void setup_specs(void) {
|
|
|
|
static void wanted_free(wanted_t *w) {
|
|
|
|
for (char **spec = gFileSpecs; spec < gFileSpecEnd; ++spec) {
|
|
|
|
for (wanted_t *w = gWantedFiles; w; w = w->next) {
|
|
|
|
// Remove trailing slashes
|
|
|
|
wanted_t *tmp = w->next;
|
|
|
|
|
|
|
|
free(w);
|
|
|
|
|
|
|
|
w = tmp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void wanted_files(size_t count, char **specs) {
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
|
|
|
|
gWantedFiles = NULL;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gFileIndexOffset)
|
|
|
|
|
|
|
|
die("Can't filter non-tarball");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove trailing slashes from specs
|
|
|
|
|
|
|
|
for (char **spec = specs; spec < specs + count; ++spec) {
|
|
|
|
char *c = *spec;
|
|
|
|
char *c = *spec;
|
|
|
|
while (*c++) ;
|
|
|
|
while (*c++) ; // forward to end
|
|
|
|
while (--c >= *spec) {
|
|
|
|
while (--c >= *spec && *c == '/')
|
|
|
|
if (*c == '/')
|
|
|
|
|
|
|
|
*c = '\0';
|
|
|
|
*c = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wanted_t *last = NULL;
|
|
|
|
|
|
|
|
for (file_index_t *f = gFileIndex; f->name; f = f->next) {
|
|
|
|
|
|
|
|
// Do we want this file?
|
|
|
|
|
|
|
|
for (char **spec = specs; spec < specs + count; ++spec) {
|
|
|
|
|
|
|
|
char *sc, *nc;
|
|
|
|
|
|
|
|
bool match = true;
|
|
|
|
|
|
|
|
for (sc = *spec, nc = f->name; *sc; ++sc, ++nc) {
|
|
|
|
|
|
|
|
if (!*nc || *sc != *nc) { // spec must be equal or prefix
|
|
|
|
|
|
|
|
match = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match && (!*nc || *nc == '/')) { // prefix must be at dir bound
|
|
|
|
static bool want_file(const char *name) {
|
|
|
|
wanted_t *w = malloc(sizeof(wanted_t));
|
|
|
|
const char *a, *b;
|
|
|
|
*w = (wanted_t){ .name = f->name, .offset = f->offset,
|
|
|
|
for (char **spec = gFileSpecs; spec < gFileSpecEnd; ++spec) {
|
|
|
|
.size = f->next->offset - f->offset, .next = NULL };
|
|
|
|
bool diff = false;
|
|
|
|
if (last) {
|
|
|
|
for (a = *spec, b = name; *a; ++a, ++b) {
|
|
|
|
last->next = w;
|
|
|
|
if (!*b || *a != *b) {
|
|
|
|
} else {
|
|
|
|
diff = true;
|
|
|
|
gWantedFiles = w;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
last = w;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!diff && (!*b || *b == '/'))
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void decode_thread(size_t thnum) {
|
|
|
|
static void decode_thread(size_t thnum) {
|
|
|
|