1.1 --- a/src/main.c Wed Jan 14 12:21:38 2009 +0000
1.2 +++ b/src/main.c Thu Mar 12 20:23:35 2009 +0000
1.3 @@ -1,6 +1,7 @@
1.4 /*
1.5 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
1.6 * Copyright (C) 2008 Red Hat, Inc
1.7 + * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
1.8 *
1.9 * This program is free software; you can redistribute it and/or modify
1.10 * it under the terms of the GNU General Public License as published by
1.11 @@ -746,8 +747,73 @@
1.12 return 0;
1.13 }
1.14
1.15 +static struct razor_set *
1.16 +relocate_packages(struct razor_set *set, struct razor_relocations *relocations)
1.17 +{
1.18 + struct razor_importer *importer;
1.19 + struct razor_property_iterator *prop_iter;
1.20 + struct razor_package_iterator *pkg_iter;
1.21 + struct razor_file_iterator *file_iter;
1.22 + struct razor_package *package;
1.23 + struct razor_property *property;
1.24 + struct razor_rpm *rpm;
1.25 + const char *name, *version, *arch, *summary, *desc, *url, *license;
1.26 + char file[PATH_MAX];
1.27 + uint32_t flags;
1.28 +
1.29 + importer = razor_importer_create();
1.30 + pkg_iter = razor_package_iterator_create(set);
1.31 +
1.32 + while (razor_package_iterator_next(pkg_iter, &package,
1.33 + RAZOR_DETAIL_NAME, &name,
1.34 + RAZOR_DETAIL_VERSION, &version,
1.35 + RAZOR_DETAIL_ARCH, &arch,
1.36 + RAZOR_DETAIL_SUMMARY, &summary,
1.37 + RAZOR_DETAIL_DESCRIPTION, &desc,
1.38 + RAZOR_DETAIL_URL, &url,
1.39 + RAZOR_DETAIL_LICENSE, &license,
1.40 + RAZOR_DETAIL_LAST)) {
1.41 + snprintf(file, sizeof file,
1.42 + "rpms/%s", rpm_filename(name, version, arch));
1.43 + rpm = razor_rpm_open(file);
1.44 + if (rpm == NULL) {
1.45 + fprintf(stderr, "failed to open rpm %s\n", file);
1.46 + razor_package_iterator_destroy(pkg_iter);
1.47 + razor_importer_destroy(importer);
1.48 + return NULL;
1.49 + }
1.50 +
1.51 + razor_relocations_set_rpm(relocations, rpm);
1.52 + razor_rpm_close(rpm);
1.53 +
1.54 + razor_importer_begin_package(importer, name, version, arch);
1.55 + razor_importer_add_details(importer,
1.56 + summary, desc, url, license);
1.57 +
1.58 + prop_iter = razor_property_iterator_create(set, package);
1.59 + while (razor_property_iterator_next(prop_iter, &property,
1.60 + &name, &flags, &version))
1.61 + razor_importer_add_property(importer,
1.62 + name, flags, version);
1.63 + razor_property_iterator_destroy(prop_iter);
1.64 +
1.65 + file_iter = razor_file_iterator_create(set, package);
1.66 + while (razor_file_iterator_next(file_iter, &name)) {
1.67 + name = razor_relocations_apply(relocations, name);
1.68 + razor_importer_add_file(importer, name);
1.69 + }
1.70 + razor_file_iterator_destroy(file_iter);
1.71 +
1.72 + razor_importer_finish_package(importer);
1.73 + }
1.74 +
1.75 + razor_package_iterator_destroy(pkg_iter);
1.76 + return razor_importer_finish(importer);
1.77 +}
1.78 +
1.79 static int
1.80 -install_packages(struct razor_set *system, struct razor_set *next)
1.81 +install_packages(struct razor_set *system, struct razor_set *next,
1.82 + struct razor_relocations *relocations)
1.83 {
1.84 struct razor_install_iterator *ii;
1.85 struct razor_package *package;
1.86 @@ -779,6 +845,8 @@
1.87 fprintf(stderr, "failed to open rpm %s\n", file);
1.88 return -1;
1.89 }
1.90 + if (relocations)
1.91 + razor_rpm_set_relocations(rpm, relocations);
1.92 if (razor_rpm_install(rpm, install_root) < 0) {
1.93 fprintf(stderr,
1.94 "failed to install rpm %s\n", file);
1.95 @@ -795,19 +863,43 @@
1.96 command_install(int argc, const char *argv[])
1.97 {
1.98 struct razor_root *root;
1.99 - struct razor_set *system, *upstream, *next;
1.100 + struct razor_relocations *relocations=NULL;
1.101 + struct razor_set *system, *upstream, *next, *set;
1.102 struct razor_transaction *trans;
1.103 - int i = 0, dependencies = 1;
1.104 -
1.105 - if (i < argc && strcmp(argv[i], "--no-dependencies") == 0) {
1.106 - dependencies = 0;
1.107 - i++;
1.108 - }
1.109 + int i, len, dependencies = 1;
1.110 + char *oldpath;
1.111
1.112 root = razor_root_open(install_root);
1.113 if (root == NULL)
1.114 return 1;
1.115
1.116 + for (i = 0; i < argc; i++) {
1.117 + if (strcmp(argv[i], "--no-dependencies") == 0)
1.118 + dependencies = 0;
1.119 + else if (strcmp(argv[i], "--relocate") == 0) {
1.120 + i++;
1.121 + if (i >= argc || strchr(argv[i], '=') == NULL) {
1.122 + fprintf(stderr,
1.123 + "Usage: razor install [OPTION...] RPM\n");
1.124 + fprintf(stderr, "Options:\n");
1.125 + fprintf(stderr, " [--no-dependencies]\n");
1.126 + fprintf(stderr,
1.127 + " [--relocate OLDPATH=NEWPATH] RPM\n");
1.128 + return -1;
1.129 + }
1.130 + len = strchr(argv[i], '=') - argv[i];
1.131 + oldpath = malloc(len + 1);
1.132 + strncpy(oldpath, argv[i], len);
1.133 + oldpath[len] = '\0';
1.134 + if (!relocations)
1.135 + relocations = razor_relocations_create();
1.136 + razor_relocations_add(relocations, oldpath,
1.137 + argv[i] + len + 1);
1.138 + free(oldpath);
1.139 + } else
1.140 + break;
1.141 + }
1.142 +
1.143 system = razor_root_get_system_set(root);
1.144 upstream = razor_set_open(rawhide_repo_filename);
1.145 if (upstream == NULL ||
1.146 @@ -818,6 +910,12 @@
1.147 return 1;
1.148 }
1.149
1.150 + if (relocations) {
1.151 + set = relocate_packages(upstream, relocations);
1.152 + razor_set_destroy(upstream);
1.153 + upstream = set;
1.154 + }
1.155 +
1.156 trans = razor_transaction_create(system, upstream);
1.157
1.158 for (; i < argc; i++) {
1.159 @@ -851,8 +949,10 @@
1.160 return 1;
1.161 }
1.162
1.163 - install_packages(system, next);
1.164 + install_packages(system, next, relocations);
1.165
1.166 + if (relocations)
1.167 + razor_relocations_destroy(relocations);
1.168 razor_set_destroy(next);
1.169 razor_set_destroy(upstream);
1.170