diff -r a69289c9080c -r 2523d03a840e librazor/importer.c --- a/librazor/importer.c Tue Jul 01 10:49:48 2008 -0400 +++ b/librazor/importer.c Wed Apr 29 17:00:01 2009 +0100 @@ -367,48 +367,56 @@ int count, i, length; struct import_entry *filenames; char *f, *end; - uint32_t name, *r; - char dirname[256]; - struct import_directory *d, root; + uint32_t name, *r, s; + char rootname[256], dirname[256]; + struct import_directory *d, *last_root; + struct array roots; struct razor_entry *e; count = importer->files.size / sizeof (struct import_entry); - razor_qsort_with_data(importer->files.data, + filenames = importer->files.data; + razor_qsort_with_data(filenames, count, sizeof (struct import_entry), compare_filenames, NULL); - root.name = hashtable_tokenize(&importer->file_table, ""); - array_init(&root.files); - array_init(&root.packages); - root.last = NULL; + array_init(&roots); + last_root = NULL; - filenames = importer->files.data; for (i = 0; i < count; i++) { f = filenames[i].name; - if (*f != '/') - continue; - f++; - - d = &root; + d = NULL; while (*f) { end = strchr(f, '/'); if (end == NULL) end = f + strlen(f); length = end - f; memcpy(dirname, f, length); - dirname[length] ='\0'; + dirname[length] = '\0'; name = hashtable_tokenize(&importer->file_table, dirname); - if (d->last == NULL || d->last->name != name) { - d->last = array_add(&d->files, sizeof *d); - d->last->name = name; - d->last->last = NULL; - array_init(&d->last->files); - array_init(&d->last->packages); + if (!d) { + if (!last_root || last_root->name != name) { + d = array_add(&roots, sizeof *d); + d->name = name; + d->last = NULL; + array_init(&d->files); + array_init(&d->packages); + last_root = d; + } + d = last_root; + } else { + if (!d->last || d->last->name != name) { + d->last = array_add(&d->files, + sizeof *d); + d->last->name = name; + d->last->last = NULL; + array_init(&d->last->files); + array_init(&d->last->packages); + } + d = d->last; } - d = d->last; f = end + 1; if (*end == '\0') break; @@ -419,16 +427,33 @@ free(filenames[i].name); } - count_entries(&root); - e = importer->set->files.data; - e->name = root.name; - e->flags = RAZOR_ENTRY_LAST; - e->start = importer->files.size ? 1 : 0; - list_set_empty(&e->packages); + count = roots.size / sizeof (struct import_directory); + d = roots.data; + s = count; + for (i = 0; i < count; i++) { + count_entries(d); + if (i) + e = array_add(&importer->set->files, sizeof *e); + else + e = importer->set->files.data; + e->name = d->name; + e->flags = 0; + e->start = d->count > 0 ? s : 0; + s += d->count; + list_set_empty(&e->packages); + d++; + } + if (count) + e->flags |= RAZOR_ENTRY_LAST; - serialize_files(importer->set, &root, &importer->set->files); + d = roots.data; + for (i = 0; i < count; i++) { + serialize_files(importer->set, d, &importer->set->files); + d++; + } array_release(&importer->files); + array_release(&roots); } static void