librazor/razor.c
author Kristian H?gsberg <krh@redhat.com>
Wed Jun 25 11:48:46 2008 -0400 (2008-06-25)
changeset 283 a510dcb8e019
parent 282 5ce341d27985
child 288 75da311eda45
child 296 4531b1390261
permissions -rw-r--r--
Also don't explode when a given path doesn't exist.
     1 /*
     2  * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
     3  * Copyright (C) 2008  Red Hat, Inc
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; either version 2 of the License, or
     8  * (at your option) any later version.
     9  *
    10  * This program is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  * GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License along
    16  * with this program; if not, write to the Free Software Foundation, Inc.,
    17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    18  */
    19 
    20 #define _GNU_SOURCE
    21 
    22 #include <stdlib.h>
    23 #include <stddef.h>
    24 #include <stdint.h>
    25 #include <stdio.h>
    26 #include <string.h>
    27 #include <sys/types.h>
    28 #include <sys/stat.h>
    29 #include <sys/mman.h>
    30 #include <unistd.h>
    31 #include <fcntl.h>
    32 #include <errno.h>
    33 #include <ctype.h>
    34 #include <fnmatch.h>
    35 
    36 #include "razor-internal.h"
    37 #include "razor.h"
    38 
    39 void *
    40 zalloc(size_t size)
    41 {
    42 	void *p;
    43 
    44 	p = malloc(size);
    45 	memset(p, 0, size);
    46 
    47 	return p;
    48 }
    49 
    50 struct razor_set_section razor_sections[] = {
    51 	{ RAZOR_STRING_POOL,	offsetof(struct razor_set, string_pool) },
    52 	{ RAZOR_PACKAGES,	offsetof(struct razor_set, packages) },
    53 	{ RAZOR_PROPERTIES,	offsetof(struct razor_set, properties) },
    54 	{ RAZOR_PACKAGE_POOL,	offsetof(struct razor_set, package_pool) },
    55 	{ RAZOR_PROPERTY_POOL,	offsetof(struct razor_set, property_pool) },
    56 };
    57 
    58 struct razor_set_section razor_files_sections[] = {
    59 	{ RAZOR_FILES,			offsetof(struct razor_set, files) },
    60 	{ RAZOR_FILE_POOL,		offsetof(struct razor_set, file_pool) },
    61 	{ RAZOR_FILE_STRING_POOL,	offsetof(struct razor_set, file_string_pool) },
    62 };
    63 
    64 struct razor_set_section razor_details_sections[] = {
    65 	{ RAZOR_DETAILS_STRING_POOL,	offsetof(struct razor_set, details_string_pool) },
    66 };
    67 
    68 RAZOR_EXPORT struct razor_set *
    69 razor_set_create(void)
    70 {
    71 	struct razor_set *set;
    72 	struct razor_entry *e;
    73 	char *empty;
    74 
    75 	set = zalloc(sizeof *set);
    76 
    77 	e = array_add(&set->files, sizeof *e);
    78 	empty = array_add(&set->string_pool, 1);
    79 	*empty = '\0';
    80 	e->name = 0;
    81 	e->flags = RAZOR_ENTRY_LAST;
    82 	e->start = 0;
    83 	list_set_empty(&e->packages);
    84 
    85 	return set;
    86 }
    87 
    88 RAZOR_EXPORT struct razor_set *
    89 razor_set_open(const char *filename)
    90 {
    91 	struct razor_set *set;
    92 	struct razor_set_section *s;
    93 	struct stat stat;
    94 	struct array *array;
    95 	int fd;
    96 
    97 	set = zalloc(sizeof *set);
    98 	fd = open(filename, O_RDONLY);
    99 	if (fstat(fd, &stat) < 0)
   100 		return NULL;
   101 	set->header = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
   102 	if (set->header == MAP_FAILED) {
   103 		free(set);
   104 		return NULL;
   105 	}
   106 
   107 	for (s = set->header->sections; ~s->type; s++) {
   108 		if (s->type >= ARRAY_SIZE(razor_sections))
   109 			continue;
   110 		if (s->type != razor_sections[s->type].type)
   111 			continue;
   112 		array = (void *) set + razor_sections[s->type].offset;
   113 		array->data = (void *) set->header + s->offset;
   114 		array->size = s->size;
   115 		array->alloc = s->size;
   116 	}
   117 	close(fd);
   118 
   119 	return set;
   120 }
   121 
   122 RAZOR_EXPORT void
   123 razor_set_open_details(struct razor_set *set, const char *filename)
   124 {
   125 	struct razor_set_section *s;
   126 	struct stat stat;
   127 	struct array *array;
   128 	int fd;
   129 
   130 	fd = open(filename, O_RDONLY);
   131 	if (fstat(fd, &stat) < 0)
   132 		return;
   133 	set->details_header = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
   134 	if (set->details_header == MAP_FAILED)
   135 		return;
   136 
   137 	for (s = set->details_header->sections; ~s->type; s++) {
   138 		if (s->type >= ARRAY_SIZE(razor_details_sections))
   139 			continue;
   140 		if (s->type != razor_details_sections[s->type].type)
   141 			continue;
   142 		array = (void *) set + razor_details_sections[s->type].offset;
   143 		array->data = (void *) set->details_header + s->offset;
   144 		array->size = s->size;
   145 		array->alloc = s->size;
   146 	}
   147 	close(fd);
   148 }
   149 
   150 RAZOR_EXPORT void
   151 razor_set_open_files(struct razor_set *set, const char *filename)
   152 {
   153 	struct razor_set_section *s;
   154 	struct stat stat;
   155 	struct array *array;
   156 	int fd;
   157 
   158 	fd = open(filename, O_RDONLY);
   159 	if (fstat(fd, &stat) < 0)
   160 		return;
   161 	set->files_header = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
   162 	if (set->files_header == MAP_FAILED)
   163 		return;
   164 
   165 	for (s = set->files_header->sections; ~s->type; s++) {
   166 		if (s->type >= ARRAY_SIZE(razor_files_sections))
   167 			continue;
   168 		if (s->type != razor_files_sections[s->type].type)
   169 			continue;
   170 		array = (void *) set + razor_files_sections[s->type].offset;
   171 		array->data = (void *) set->files_header + s->offset;
   172 		array->size = s->size;
   173 		array->alloc = s->size;
   174 	}
   175 	close(fd);
   176 }
   177 
   178 RAZOR_EXPORT void
   179 razor_set_destroy(struct razor_set *set)
   180 {
   181 	unsigned int size;
   182 	struct array *a;
   183 	int i;
   184 
   185 	if (set->header) {
   186 		for (i = 0; set->header->sections[i].type; i++)
   187 			;
   188 		size = set->header->sections[i].type;
   189 		munmap(set->header, size);
   190 	} else {
   191 		for (i = 0; i < ARRAY_SIZE(razor_sections); i++) {
   192 			a = (void *) set + razor_sections[i].offset;
   193 			free(a->data);
   194 		}
   195 	}
   196 
   197 	if (set->details_header) {
   198 		for (i = 0; set->details_header->sections[i].type; i++)
   199 			;
   200 		size = set->details_header->sections[i].type;
   201 		munmap(set->details_header, size);
   202 	} else {
   203 		for (i = 0; i < ARRAY_SIZE(razor_details_sections); i++) {
   204 			a = (void *) set + razor_details_sections[i].offset;
   205 			free(a->data);
   206 		}
   207 	}
   208 
   209 	if (set->files_header) {
   210 		for (i = 0; set->files_header->sections[i].type; i++)
   211 			;
   212 		size = set->files_header->sections[i].type;
   213 		munmap(set->files_header, size);
   214 	} else {
   215 		for (i = 0; i < ARRAY_SIZE(razor_files_sections); i++) {
   216 			a = (void *) set + razor_files_sections[i].offset;
   217 			free(a->data);
   218 		}
   219 	}
   220 
   221 	free(set);
   222 }
   223 
   224 static int
   225 razor_set_write_sections_to_fd(struct razor_set *set, int fd, int magic,
   226 			       struct razor_set_section *sections,
   227 			       size_t array_size)
   228 {
   229 	char data[4096];
   230 	struct razor_set_header *header = (struct razor_set_header *) data;
   231 	struct array *a;
   232 	uint32_t offset;
   233 	int i;
   234 
   235 	memset(data, 0, sizeof data);
   236 	header->magic = magic;
   237 	header->version = RAZOR_VERSION;
   238 	offset = sizeof data;
   239 
   240 	for (i = 0; i < array_size; i++) {
   241 		if (sections[i].type != i)
   242 			continue;
   243 		a = (void *) set + sections[i].offset;
   244 		header->sections[i].type = i;
   245 		header->sections[i].offset = offset;
   246 		header->sections[i].size = a->size;
   247 		offset += ALIGN(a->size, 4096);
   248 	}
   249 
   250 	header->sections[i].type = ~0;
   251 	header->sections[i].offset = 0;
   252 	header->sections[i].size = 0;
   253 
   254 	razor_write(fd, data, sizeof data);
   255 	memset(data, 0, sizeof data);
   256 	for (i = 0; i < array_size; i++) {
   257 		if (sections[i].type != i)
   258 			continue;
   259 		a = (void *) set + sections[i].offset;
   260 		razor_write(fd, a->data, a->size);
   261 		razor_write(fd, data, ALIGN(a->size, 4096) - a->size);
   262 	}
   263 
   264 	return 0;
   265 }
   266 
   267 RAZOR_EXPORT int
   268 razor_set_write_to_fd(struct razor_set *set, int fd,
   269 		      enum razor_repo_file_type type)
   270 {
   271 	switch (type) {
   272 	case RAZOR_REPO_FILE_MAIN:
   273 		return razor_set_write_sections_to_fd(set, fd, RAZOR_MAGIC,
   274 						      razor_sections,
   275 						      ARRAY_SIZE(razor_sections));
   276 
   277 	case RAZOR_REPO_FILE_DETAILS:
   278 		return razor_set_write_sections_to_fd(set, fd, RAZOR_DETAILS_MAGIC,
   279 						      razor_details_sections,
   280 						      ARRAY_SIZE(razor_details_sections));
   281 	case RAZOR_REPO_FILE_FILES:
   282 		return razor_set_write_sections_to_fd(set, fd, RAZOR_FILES_MAGIC,
   283 						      razor_files_sections,
   284 						      ARRAY_SIZE(razor_files_sections));
   285 	default:
   286 		return -1;
   287 	}
   288 }
   289 
   290 RAZOR_EXPORT int
   291 razor_set_write(struct razor_set *set, const char *filename,
   292 		enum razor_repo_file_type type)
   293 {
   294 	int fd, status;
   295 
   296 	fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
   297 	if (fd < 0)
   298 		return -1;
   299 
   300 	status = razor_set_write_to_fd(set, fd, type);
   301 	if (status) {
   302 	    close(fd);
   303 	    return status;
   304 	}
   305 
   306 	return close(fd);
   307 }
   308 
   309 RAZOR_EXPORT void
   310 razor_build_evr(char *evr_buf, int size, const char *epoch,
   311 		const char *version, const char *release)
   312 {
   313 	int len;
   314 
   315 	if (!version || !*version) {
   316 		*evr_buf = '\0';
   317 		return;
   318 	}
   319 
   320 	if (epoch && *epoch && strcmp(epoch, "0") != 0) {
   321 		len = snprintf(evr_buf, size, "%s:", epoch);
   322 		evr_buf += len;
   323 		size -= len;
   324 	}
   325 	len = snprintf(evr_buf, size, "%s", version);
   326 	evr_buf += len;
   327 	size -= len;
   328 	if (release && *release)
   329 		snprintf(evr_buf, size, "-%s", release);
   330 }
   331 
   332 RAZOR_EXPORT int
   333 razor_versioncmp(const char *s1, const char *s2)
   334 {
   335 	const char *p1, *p2;
   336 	long n1, n2;
   337 	int res;
   338 
   339 	n1 = strtol(s1, (char **) &p1, 10);
   340 	n2 = strtol(s2, (char **) &p2, 10);
   341 
   342 	/* Epoch; if one but not the other has an epoch set, default
   343 	 * the epoch-less version to 0. */
   344 	res = (*p1 == ':') - (*p2 == ':');
   345 	if (res < 0) {
   346 		n1 = 0;
   347 		p1 = s1;
   348 		p2++;
   349 	} else if (res > 0) {
   350 		p1++;
   351 		n2 = 0;
   352 		p2 = s2;
   353 	}
   354 
   355 	if (n1 != n2)
   356 		return n1 - n2;
   357 	while (*p1 && *p2) {
   358 		if (*p1 != *p2)
   359 			return *p1 - *p2;
   360 		p1++;
   361 		p2++;
   362 		if (isdigit(*p1) && isdigit(*p2))
   363 			return razor_versioncmp(p1, p2);
   364 	}
   365 
   366 	return *p1 - *p2;
   367 }
   368 
   369 RAZOR_EXPORT struct razor_package *
   370 razor_set_get_package(struct razor_set *set, const char *package)
   371 {
   372 	struct razor_package_iterator *pi;
   373 	struct razor_package *p;
   374 	const char *name, *version, *arch;
   375 
   376 	pi = razor_package_iterator_create(set);
   377 	while (razor_package_iterator_next(pi, &p, &name, &version, &arch)) {
   378 		if (strcmp(package, name) == 0)
   379 			break;
   380 	}
   381 	razor_package_iterator_destroy(pi);
   382 
   383 	return p;
   384 }
   385 
   386 RAZOR_EXPORT void
   387 razor_package_get_details(struct razor_set *set,
   388 			  struct razor_package *package,
   389 			  const char **summary, const char **description,
   390 			  const char **url, const char **license)
   391 {
   392 	const char *pool = set->details_string_pool.data;
   393 
   394 	*summary = &pool[package->summary];
   395 	*description = &pool[package->description];
   396 	*url = &pool[package->url];
   397 	*license = &pool[package->license];
   398 }
   399 
   400 RAZOR_EXPORT const char *
   401 razor_property_relation_to_string(struct razor_property *p)
   402 {
   403 	switch (p->flags & RAZOR_PROPERTY_RELATION_MASK) {
   404 	case RAZOR_PROPERTY_LESS:
   405 		return "<";
   406 
   407 	case RAZOR_PROPERTY_LESS | RAZOR_PROPERTY_EQUAL:
   408 		return "<=";
   409 
   410 	case RAZOR_PROPERTY_EQUAL:
   411 		return "=";
   412 
   413 	case RAZOR_PROPERTY_GREATER | RAZOR_PROPERTY_EQUAL:
   414 		return ">=";
   415 
   416 	case RAZOR_PROPERTY_GREATER:
   417 		return ">";
   418 
   419 	default:
   420 		return "?";
   421 	}
   422 }
   423 
   424 RAZOR_EXPORT const char *
   425 razor_property_type_to_string(struct razor_property *p)
   426 {
   427 	switch (p->flags & RAZOR_PROPERTY_TYPE_MASK) {
   428 	case RAZOR_PROPERTY_REQUIRES:
   429 		return "requires";
   430 	case RAZOR_PROPERTY_PROVIDES:
   431 		return "provides";
   432 	case RAZOR_PROPERTY_CONFLICTS:
   433 		return "conflicts";
   434 	case RAZOR_PROPERTY_OBSOLETES:
   435 		return "obsoletes";
   436 	default:
   437 		return NULL;
   438 	}
   439 }
   440 
   441 RAZOR_EXPORT struct razor_entry *
   442 razor_set_find_entry(struct razor_set *set,
   443 		     struct razor_entry *dir, const char *pattern)
   444 {
   445 	struct razor_entry *e;
   446 	const char *n, *pool = set->file_string_pool.data;
   447 	int len;
   448 
   449 	e = (struct razor_entry *) set->files.data + dir->start;
   450 	do {
   451 		n = pool + e->name;
   452 		if (strcmp(pattern + 1, n) == 0)
   453 			return e;
   454 		len = strlen(n);
   455 		if (e->start != 0 && strncmp(pattern + 1, n, len) == 0 &&
   456 		    pattern[len + 1] == '/') {
   457 			return razor_set_find_entry(set, e, pattern + len + 1);
   458 		}
   459 	} while (!((e++)->flags & RAZOR_ENTRY_LAST));
   460 
   461 	return NULL;
   462 }
   463 
   464 static void
   465 list_dir(struct razor_set *set, struct razor_entry *dir,
   466 	 char *prefix, const char *pattern)
   467 {
   468 	struct razor_entry *e;
   469 	const char *n, *pool = set->file_string_pool.data;
   470 
   471 	e = (struct razor_entry *) set->files.data + dir->start;
   472 	do {
   473 		n = pool + e->name;
   474 		if (pattern && pattern[0] && fnmatch(pattern, n, 0) != 0)
   475 			continue;
   476 		printf("%s/%s\n", prefix, n);
   477 		if (e->start) {
   478 			char *sub = prefix + strlen (prefix);
   479 			*sub = '/';
   480 			strcpy (sub + 1, n);
   481 			list_dir(set, e, prefix, pattern);
   482 			*sub = '\0';
   483 		}
   484 	} while (!((e++)->flags & RAZOR_ENTRY_LAST));
   485 }
   486 
   487 RAZOR_EXPORT void
   488 razor_set_list_files(struct razor_set *set, const char *pattern)
   489 {
   490 	struct razor_entry *e;
   491 	char buffer[512], *p, *base;
   492 
   493 	if (pattern == NULL || !strcmp (pattern, "/")) {
   494 		buffer[0] = '\0';
   495 		list_dir(set, set->files.data, buffer, NULL);
   496 		return;
   497 	}
   498 
   499 	strcpy(buffer, pattern);
   500 	e = razor_set_find_entry(set, set->files.data, buffer);
   501 	if (e && e->start > 0) {
   502 		base = NULL;
   503 	} else {
   504 		p = strrchr(buffer, '/');
   505 		if (p) {
   506 			*p = '\0';
   507 			base = p + 1;
   508 		} else {
   509 			base = NULL;
   510 		}
   511 	}
   512 	e = razor_set_find_entry(set, set->files.data, buffer);
   513 	if (e && e->start != 0)
   514 		list_dir(set, e, buffer, base);
   515 }
   516 
   517 static struct list *
   518 list_package_files(struct razor_set *set, struct list *r,
   519 		   struct razor_entry *dir, uint32_t end,
   520 		   char *prefix)
   521 {
   522 	struct razor_entry *e, *f, *entries;
   523 	uint32_t next, file;
   524 	char *pool;
   525 	int len;
   526 
   527 	entries = (struct razor_entry *) set->files.data;
   528 	pool = set->file_string_pool.data;
   529 
   530 	e = entries + dir->start;
   531 	do {
   532 		if (entries + r->data == e) {
   533 			printf("%s/%s\n", prefix, pool + e->name);
   534 			r = list_next(r);
   535 			if (!r)
   536 				return NULL;
   537 			if (r->data >= end)
   538 				return r;
   539 		}
   540 	} while (!((e++)->flags & RAZOR_ENTRY_LAST));
   541 
   542 	e = entries + dir->start;
   543 	do {
   544 		if (e->start == 0)
   545 			continue;
   546 
   547 		if (e->flags & RAZOR_ENTRY_LAST)
   548 			next = end;
   549 		else {
   550 			f = e + 1;
   551 			while (f->start == 0 && !(f->flags & RAZOR_ENTRY_LAST))
   552 				f++;
   553 			if (f->start == 0)
   554 				next = end;
   555 			else
   556 				next = f->start;
   557 		}
   558 
   559 		file = r->data;
   560 		if (e->start <= file && file < next) {
   561 			len = strlen(prefix);
   562 			prefix[len] = '/';
   563 			strcpy(prefix + len + 1, pool + e->name);
   564 			r = list_package_files(set, r, e, next, prefix);
   565 			prefix[len] = '\0';
   566 		}
   567 	} while (!((e++)->flags & RAZOR_ENTRY_LAST) && r != NULL);
   568 
   569 	return r;
   570 }
   571 
   572 RAZOR_EXPORT void
   573 razor_set_list_package_files(struct razor_set *set, const char *name)
   574 {
   575 	struct razor_package *package;
   576 	struct list *r;
   577 	uint32_t end;
   578 	char buffer[512];
   579 
   580 	package = razor_set_get_package(set, name);
   581 	/* TODO: we should return the error to the caller */
   582 	if (!package)
   583 		return;
   584 
   585 	r = list_first(&package->files, &set->file_pool);
   586 	end = set->files.size / sizeof (struct razor_entry);
   587 	buffer[0] = '\0';
   588 	list_package_files(set, r, set->files.data, end, buffer);
   589 }
   590 
   591 /* The diff order matters.  We should sort the packages so that a
   592  * REMOVE of a package comes before the INSTALL, and so that all
   593  * requires for a package have been installed before the package.
   594  **/
   595 
   596 RAZOR_EXPORT void
   597 razor_set_diff(struct razor_set *set, struct razor_set *upstream,
   598 	       razor_diff_callback_t callback, void *data)
   599 {
   600  	struct razor_package_iterator *pi1, *pi2;
   601  	struct razor_package *p1, *p2;
   602 	const char *name1, *name2, *version1, *version2, *arch1, *arch2;
   603 	int res;
   604 
   605 	pi1 = razor_package_iterator_create(set);
   606 	pi2 = razor_package_iterator_create(upstream);
   607 
   608 	razor_package_iterator_next(pi1, &p1, &name1, &version1, &arch1);
   609 	razor_package_iterator_next(pi2, &p2, &name2, &version2, &arch2);
   610 
   611 	while (p1 || p2) {
   612 		if (p1 && p2) {
   613 			res = strcmp(name1, name2);
   614 			if (res == 0)
   615 				res = razor_versioncmp(version1, version2);
   616 		} else {
   617 			res = 0;
   618 		}
   619 
   620 		if (p2 == NULL || res < 0)
   621 			callback(RAZOR_DIFF_ACTION_REMOVE,
   622 				 p1, name1, version1, arch1, data);
   623 		else if (p1 == NULL || res > 0)
   624 			callback(RAZOR_DIFF_ACTION_ADD,
   625 				 p2, name2, version2, arch2, data);
   626 
   627 		if (p1 != NULL && res <= 0)
   628 			razor_package_iterator_next(pi1, &p1,
   629 						    &name1, &version1, &arch1);
   630 		if (p2 != NULL && res >= 0)
   631 			razor_package_iterator_next(pi2, &p2,
   632 						    &name2, &version2, &arch2);
   633 	}
   634 
   635 	razor_package_iterator_destroy(pi1);
   636 	razor_package_iterator_destroy(pi2);
   637 }
   638 
   639 static void
   640 add_new_package(enum razor_diff_action action,
   641 		struct razor_package *package,
   642 		const char *name,
   643 		const char *version,
   644 		const char *arch,
   645 		void *data)
   646 {
   647 	if (action == RAZOR_DIFF_ACTION_ADD)
   648 		razor_package_query_add_package(data, package);
   649 }
   650 
   651 RAZOR_EXPORT struct razor_package_iterator *
   652 razor_set_create_remove_iterator(struct razor_set *set,
   653 				 struct razor_set *next)
   654 {
   655 	struct razor_package_query *query;
   656 	struct razor_package_iterator *pi;
   657 
   658 	query = razor_package_query_create(set);
   659 	razor_set_diff(next, set, add_new_package, query);
   660 
   661 	pi = razor_package_query_finish(query);
   662 
   663 	/* FIXME: We need to figure out the right install order here,
   664 	 * so the post and pre scripts can run. */
   665 
   666 	/* sort */
   667 
   668 	return pi;
   669 }
   670 
   671 RAZOR_EXPORT struct razor_package_iterator *
   672 razor_set_create_install_iterator(struct razor_set *set,
   673 				  struct razor_set *next)
   674 {
   675 	struct razor_package_query *query;
   676 	struct razor_package_iterator *pi;
   677 
   678 	query = razor_package_query_create(next);
   679 	razor_set_diff(set, next, add_new_package, query);
   680 
   681 	pi = razor_package_query_finish(query);
   682 
   683 	/* FIXME: We need to figure out the right install order here,
   684 	 * so the post and pre scripts can run. */
   685 
   686 	/* sort */
   687 
   688 	return pi;
   689 }