librazor/importer.c
changeset 363 c75a2d5caae9
parent 309 a69289c9080c
child 369 f8c27fe9fe63
     1.1 --- a/librazor/importer.c	Tue Jul 01 10:49:48 2008 -0400
     1.2 +++ b/librazor/importer.c	Fri May 01 16:48:47 2009 +0100
     1.3 @@ -367,48 +367,56 @@
     1.4  	int count, i, length;
     1.5  	struct import_entry *filenames;
     1.6  	char *f, *end;
     1.7 -	uint32_t name, *r;
     1.8 -	char dirname[256];
     1.9 -	struct import_directory *d, root;
    1.10 +	uint32_t name, *r, s;
    1.11 +	char rootname[256], dirname[256];
    1.12 +	struct import_directory *d, *last_root;
    1.13 +	struct array roots;
    1.14  	struct razor_entry *e;
    1.15  
    1.16  	count = importer->files.size / sizeof (struct import_entry);
    1.17 -	razor_qsort_with_data(importer->files.data,
    1.18 +	filenames = importer->files.data;
    1.19 +	razor_qsort_with_data(filenames,
    1.20  			      count,
    1.21  			      sizeof (struct import_entry),
    1.22  			      compare_filenames,
    1.23  			      NULL);
    1.24  
    1.25 -	root.name = hashtable_tokenize(&importer->file_table, "");
    1.26 -	array_init(&root.files);
    1.27 -	array_init(&root.packages);
    1.28 -	root.last = NULL;
    1.29 +	array_init(&roots);
    1.30 +	last_root = NULL;
    1.31  
    1.32 -	filenames = importer->files.data;
    1.33  	for (i = 0; i < count; i++) {
    1.34  		f = filenames[i].name;
    1.35 -		if (*f != '/')
    1.36 -			continue;
    1.37 -		f++;
    1.38 -
    1.39 -		d = &root;
    1.40 +		d = NULL;
    1.41  		while (*f) {
    1.42  			end = strchr(f, '/');
    1.43  			if (end == NULL)
    1.44  				end = f + strlen(f);
    1.45  			length = end - f;
    1.46  			memcpy(dirname, f, length);
    1.47 -			dirname[length] ='\0';
    1.48 +			dirname[length] = '\0';
    1.49  			name = hashtable_tokenize(&importer->file_table,
    1.50  						  dirname);
    1.51 -			if (d->last == NULL || d->last->name != name) {
    1.52 -				d->last = array_add(&d->files, sizeof *d);
    1.53 -				d->last->name = name;
    1.54 -				d->last->last = NULL;
    1.55 -				array_init(&d->last->files);
    1.56 -				array_init(&d->last->packages);
    1.57 +			if (!d) {
    1.58 +				if (!last_root || last_root->name != name) {
    1.59 +					d = array_add(&roots, sizeof *d);
    1.60 +					d->name = name;
    1.61 +					d->last = NULL;
    1.62 +					array_init(&d->files);
    1.63 +					array_init(&d->packages);
    1.64 +					last_root = d;
    1.65 +				}
    1.66 +				d = last_root;
    1.67 +			} else {
    1.68 +				if (!d->last || d->last->name != name) {
    1.69 +					d->last = array_add(&d->files,
    1.70 +							    sizeof *d);
    1.71 +					d->last->name = name;
    1.72 +					d->last->last = NULL;
    1.73 +					array_init(&d->last->files);
    1.74 +					array_init(&d->last->packages);
    1.75 +				}
    1.76 +				d = d->last;
    1.77  			}
    1.78 -			d = d->last;
    1.79  			f = end + 1;
    1.80  			if (*end == '\0')
    1.81  				break;
    1.82 @@ -419,16 +427,33 @@
    1.83  		free(filenames[i].name);
    1.84  	}
    1.85  
    1.86 -	count_entries(&root);
    1.87 -	e = importer->set->files.data;
    1.88 -	e->name = root.name;
    1.89 -	e->flags = RAZOR_ENTRY_LAST;
    1.90 -	e->start = importer->files.size ? 1 : 0;
    1.91 -	list_set_empty(&e->packages);
    1.92 +	count = roots.size / sizeof (struct import_directory);
    1.93 +	d = roots.data;
    1.94 +	s = count;
    1.95 +	for (i = 0; i < count; i++) {
    1.96 +		count_entries(d);
    1.97 +		if (i)
    1.98 +			e = array_add(&importer->set->files, sizeof *e);
    1.99 +		else
   1.100 +			e = importer->set->files.data;
   1.101 +		e->name = d->name;
   1.102 +		e->flags = 0;
   1.103 +		e->start = d->count > 0 ? s : 0;
   1.104 +		s += d->count;
   1.105 +		list_set_empty(&e->packages);
   1.106 +		d++;
   1.107 +	}
   1.108 +	if (count)
   1.109 +		e->flags |= RAZOR_ENTRY_LAST;
   1.110  
   1.111 -	serialize_files(importer->set, &root, &importer->set->files);
   1.112 +	d = roots.data;
   1.113 +	for (i = 0; i < count; i++) {
   1.114 +		serialize_files(importer->set, d, &importer->set->files);
   1.115 +		d++;
   1.116 +	}
   1.117  
   1.118  	array_release(&importer->files);
   1.119 +	array_release(&roots);
   1.120  }
   1.121  
   1.122  static void