1.1 --- a/main.c Thu Mar 06 01:33:08 2008 -0500
1.2 +++ b/main.c Fri Mar 07 08:24:09 2008 -0500
1.3 @@ -11,9 +11,12 @@
1.4 #include "razor.h"
1.5 #include "razor-internal.h"
1.6
1.7 -static const char *repo_filename = "system.repo";
1.8 -static const char *rawhide_repo_filename = "rawhide.repo";
1.9 -static const char *updated_repo_filename = "system-updated.repo";
1.10 +static const char system_repo_filename[] = "system.repo";
1.11 +static const char rawhide_repo_filename[] = "rawhide.repo";
1.12 +static const char updated_repo_filename[] = "system-updated.repo";
1.13 +static const char razor_root_path[] = "/var/lib/razor";
1.14 +static const char root[] = "install";
1.15 +static const char *repo_filename = system_repo_filename;
1.16
1.17 static int
1.18 command_list(int argc, const char *argv[])
1.19 @@ -452,27 +455,98 @@
1.20 return 0;
1.21 }
1.22
1.23 -const static char razor_root_path[] = "/var/lib/razor";
1.24 -const static char razor_system_repo[] = "system.repo";
1.25 -const static char root[] = "install";
1.26 +static struct razor_set *
1.27 +create_set_from_rpms(int argc, const char *argv[])
1.28 +{
1.29 + struct razor_importer *importer;
1.30 + struct razor_rpm *rpm;
1.31 + int i;
1.32 +
1.33 + importer = razor_importer_new();
1.34 + for (i = 0; i < argc; i++) {
1.35 + rpm = razor_rpm_open(argv[i]);
1.36 + if (rpm == NULL) {
1.37 + fprintf(stderr,
1.38 + "failed to open rpm \"%s\"\n", argv[i]);
1.39 + continue;
1.40 + }
1.41 + if (razor_importer_add_rpm(importer, rpm)) {
1.42 + fprintf(stderr, "couldn't import %s\n", argv[i]);
1.43 + break;
1.44 + }
1.45 + razor_rpm_close(rpm);
1.46 + }
1.47 +
1.48 + return razor_importer_finish(importer);
1.49 +}
1.50 +
1.51 +static char **
1.52 +list_packages(int count, struct razor_set *set)
1.53 +{
1.54 + struct razor_package_iterator *pi;
1.55 + struct razor_package *package;
1.56 + const char *name, *version;
1.57 + char **packages;
1.58 + int i;
1.59 +
1.60 + packages = malloc(count * sizeof *packages);
1.61 + pi = razor_package_iterator_create(set);
1.62 + i = 0;
1.63 + while (razor_package_iterator_next(pi, &package, &name, &version))
1.64 + packages[i] = strdup(name);
1.65 + razor_package_iterator_destroy(pi);
1.66 +
1.67 + return packages;
1.68 +}
1.69
1.70 static int
1.71 command_install(int argc, const char *argv[])
1.72 {
1.73 + struct razor_set *system, *upstream, *new;
1.74 + struct razor_transaction *trans;
1.75 struct razor_rpm *rpm;
1.76 - const char *filename = argv[0];
1.77 + const char *filename;
1.78 + char path[PATH_MAX], **packages;
1.79 + int i;
1.80
1.81 - rpm = razor_rpm_open(filename);
1.82 - if (rpm == NULL) {
1.83 - fprintf(stderr, "failed to open rpm %s\n", filename);
1.84 + upstream = create_set_from_rpms(argc, argv);
1.85 + snprintf(path, sizeof path,
1.86 + "%s%s/%s", root, razor_root_path, system_repo_filename);
1.87 + system = razor_set_open(path);
1.88 + if (system == NULL) {
1.89 + fprintf(stderr, "couldn't open system package database\n");
1.90 return -1;
1.91 }
1.92 - if (razor_rpm_install(rpm, root) < 0) {
1.93 - fprintf(stderr, "failed to install rpm %s\n", filename);
1.94 - return -1;
1.95 - }
1.96 -
1.97 - razor_rpm_close(rpm);
1.98 +
1.99 + packages = list_packages(argc, upstream);
1.100 + trans = razor_transaction_create(system, upstream,
1.101 + argc, packages, 0, NULL);
1.102 + razor_transaction_describe(trans);
1.103 + if (trans->errors)
1.104 + return 1;
1.105 +
1.106 + /* FIXME: Use _finish() convention here? That is, a function
1.107 + * that starts the computation and returns the result while
1.108 + * destroying the transaction. Nice for transient objects
1.109 + * such as the merger and the importer. Should we do that for
1.110 + * transactions too, that is, razor_transaction_finish()? */
1.111 + new = razor_transaction_run(trans);
1.112 + razor_transaction_destroy(trans);
1.113 +
1.114 + for (i = 0; i < argc; i++) {
1.115 + filename = argv[i];
1.116 + rpm = razor_rpm_open(argv[i]);
1.117 + if (rpm == NULL) {
1.118 + fprintf(stderr, "failed to open rpm %s\n", filename);
1.119 + return -1;
1.120 + }
1.121 + if (razor_rpm_install(rpm, root) < 0) {
1.122 + fprintf(stderr,
1.123 + "failed to install rpm %s\n", filename);
1.124 + return -1;
1.125 + }
1.126 + razor_rpm_close(rpm);
1.127 + }
1.128
1.129 return 0;
1.130 }
1.131 @@ -507,7 +581,7 @@
1.132
1.133 set = razor_set_create();
1.134 snprintf(path, sizeof path, "%s%s/%s",
1.135 - root, razor_root_path, razor_system_repo);
1.136 + root, razor_root_path, system_repo_filename);
1.137 if (razor_set_write(set, path) < 0) {
1.138 fprintf(stderr, "could not write initial package set\n");
1.139 return -1;