diff -r 1555934cfb04 -r cf0fdfe5bca2 src/main.c --- a/src/main.c Wed Jan 14 12:21:38 2009 +0000 +++ b/src/main.c Thu Mar 12 20:23:35 2009 +0000 @@ -1,6 +1,7 @@ /* * Copyright (C) 2008 Kristian Høgsberg * Copyright (C) 2008 Red Hat, Inc + * Copyright (C) 2009 J. Ali Harlow * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -746,8 +747,73 @@ return 0; } +static struct razor_set * +relocate_packages(struct razor_set *set, struct razor_relocations *relocations) +{ + struct razor_importer *importer; + struct razor_property_iterator *prop_iter; + struct razor_package_iterator *pkg_iter; + struct razor_file_iterator *file_iter; + struct razor_package *package; + struct razor_property *property; + struct razor_rpm *rpm; + const char *name, *version, *arch, *summary, *desc, *url, *license; + char file[PATH_MAX]; + uint32_t flags; + + importer = razor_importer_create(); + pkg_iter = razor_package_iterator_create(set); + + while (razor_package_iterator_next(pkg_iter, &package, + RAZOR_DETAIL_NAME, &name, + RAZOR_DETAIL_VERSION, &version, + RAZOR_DETAIL_ARCH, &arch, + RAZOR_DETAIL_SUMMARY, &summary, + RAZOR_DETAIL_DESCRIPTION, &desc, + RAZOR_DETAIL_URL, &url, + RAZOR_DETAIL_LICENSE, &license, + RAZOR_DETAIL_LAST)) { + snprintf(file, sizeof file, + "rpms/%s", rpm_filename(name, version, arch)); + rpm = razor_rpm_open(file); + if (rpm == NULL) { + fprintf(stderr, "failed to open rpm %s\n", file); + razor_package_iterator_destroy(pkg_iter); + razor_importer_destroy(importer); + return NULL; + } + + razor_relocations_set_rpm(relocations, rpm); + razor_rpm_close(rpm); + + razor_importer_begin_package(importer, name, version, arch); + razor_importer_add_details(importer, + summary, desc, url, license); + + prop_iter = razor_property_iterator_create(set, package); + while (razor_property_iterator_next(prop_iter, &property, + &name, &flags, &version)) + razor_importer_add_property(importer, + name, flags, version); + razor_property_iterator_destroy(prop_iter); + + file_iter = razor_file_iterator_create(set, package); + while (razor_file_iterator_next(file_iter, &name)) { + name = razor_relocations_apply(relocations, name); + razor_importer_add_file(importer, name); + } + razor_file_iterator_destroy(file_iter); + + razor_importer_finish_package(importer); + } + + razor_package_iterator_destroy(pkg_iter); + return razor_importer_finish(importer); +} + static int -install_packages(struct razor_set *system, struct razor_set *next) +install_packages(struct razor_set *system, struct razor_set *next, + struct razor_relocations *relocations) { struct razor_install_iterator *ii; struct razor_package *package; @@ -779,6 +845,8 @@ fprintf(stderr, "failed to open rpm %s\n", file); return -1; } + if (relocations) + razor_rpm_set_relocations(rpm, relocations); if (razor_rpm_install(rpm, install_root) < 0) { fprintf(stderr, "failed to install rpm %s\n", file); @@ -795,19 +863,43 @@ command_install(int argc, const char *argv[]) { struct razor_root *root; - struct razor_set *system, *upstream, *next; + struct razor_relocations *relocations=NULL; + struct razor_set *system, *upstream, *next, *set; struct razor_transaction *trans; - int i = 0, dependencies = 1; - - if (i < argc && strcmp(argv[i], "--no-dependencies") == 0) { - dependencies = 0; - i++; - } + int i, len, dependencies = 1; + char *oldpath; root = razor_root_open(install_root); if (root == NULL) return 1; + for (i = 0; i < argc; i++) { + if (strcmp(argv[i], "--no-dependencies") == 0) + dependencies = 0; + else if (strcmp(argv[i], "--relocate") == 0) { + i++; + if (i >= argc || strchr(argv[i], '=') == NULL) { + fprintf(stderr, + "Usage: razor install [OPTION...] RPM\n"); + fprintf(stderr, "Options:\n"); + fprintf(stderr, " [--no-dependencies]\n"); + fprintf(stderr, + " [--relocate OLDPATH=NEWPATH] RPM\n"); + return -1; + } + len = strchr(argv[i], '=') - argv[i]; + oldpath = malloc(len + 1); + strncpy(oldpath, argv[i], len); + oldpath[len] = '\0'; + if (!relocations) + relocations = razor_relocations_create(); + razor_relocations_add(relocations, oldpath, + argv[i] + len + 1); + free(oldpath); + } else + break; + } + system = razor_root_get_system_set(root); upstream = razor_set_open(rawhide_repo_filename); if (upstream == NULL || @@ -818,6 +910,12 @@ return 1; } + if (relocations) { + set = relocate_packages(upstream, relocations); + razor_set_destroy(upstream); + upstream = set; + } + trans = razor_transaction_create(system, upstream); for (; i < argc; i++) { @@ -851,8 +949,10 @@ return 1; } - install_packages(system, next); + install_packages(system, next, relocations); + if (relocations) + razor_relocations_destroy(relocations); razor_set_destroy(next); razor_set_destroy(upstream);