summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/import-rpmdb.c2
-rw-r--r--src/import-yum.c2
-rw-r--r--src/main.c167
-rw-r--r--src/rpm.c41
4 files changed, 108 insertions, 104 deletions
diff --git a/src/import-rpmdb.c b/src/import-rpmdb.c
index a373786..3b4851c 100644
--- a/src/import-rpmdb.c
+++ b/src/import-rpmdb.c
@@ -98,7 +98,7 @@ razor_set_create_from_rpmdb(void)
exit(1);
}
- importer = razor_importer_new();
+ importer = razor_importer_create();
iter = rpmdbInitIterator(db, 0, NULL, 0);
while (h = rpmdbNextIterator(iter), h != NULL) {
diff --git a/src/import-yum.c b/src/import-yum.c
index 8132eb8..cb4ea7a 100644
--- a/src/import-yum.c
+++ b/src/import-yum.c
@@ -285,7 +285,7 @@ razor_set_create_from_yum(void)
gzFile primary, filelists;
XML_ParsingStatus status;
- ctx.importer = razor_importer_new();
+ ctx.importer = razor_importer_create();
ctx.state = YUM_STATE_BEGIN;
ctx.primary_parser = XML_ParserCreate(NULL);
diff --git a/src/main.c b/src/main.c
index 15b3b6e..f9aee35 100644
--- a/src/main.c
+++ b/src/main.c
@@ -446,9 +446,12 @@ command_update(int argc, const char *argv[])
}
}
- errors = razor_transaction_resolve(trans);
- if (errors)
+ razor_transaction_resolve(trans);
+ errors = razor_transaction_describe(trans);
+ if (errors) {
+ fprintf(stderr, "unresolved dependencies\n");
return 1;
+ }
set = razor_transaction_finish(trans);
razor_set_write(set, updated_repo_filename, RAZOR_REPO_FILE_MAIN);
@@ -493,14 +496,17 @@ command_remove(int argc, const char *argv[])
}
static void
-print_diff(const char *name,
- const char *old_version, const char *new_version, const char *arch,
+print_diff(enum razor_diff_action action,
+ struct razor_package *package,
+ const char *name,
+ const char *version,
+ const char *arch,
void *data)
{
- if (old_version)
- printf("removing %s %s\n", name, old_version);
- else
- printf("install %s %s\n", name, new_version);
+ if (action == RAZOR_DIFF_ACTION_ADD)
+ printf("install %s-%s.%s\n", name, version, arch);
+ if (action == RAZOR_DIFF_ACTION_REMOVE)
+ printf("remove %s-%s.%s\n", name, version, arch);
}
static int
@@ -544,7 +550,7 @@ command_import_rpms(int argc, const char *argv[])
return -1;
}
- importer = razor_importer_new();
+ importer = razor_importer_create();
while (de = readdir(dir), de != NULL) {
len = strlen(de->d_name);
@@ -579,79 +585,93 @@ command_import_rpms(int argc, const char *argv[])
return 0;
}
-static void
-download_package(const char *name,
- const char *old_version,
- const char *new_version,
- const char *arch,
- void *data)
+static const char *
+rpm_filename(const char *name, const char *version, const char *arch)
{
- char file[PATH_MAX], url[256];
- const char *v;
- int *errors = data;
+ static char file[PATH_MAX];
+ const char *v;
+
+ /* Skip epoch */
+ v = strchr(version, ':');
+ if (v != NULL)
+ v = v + 1;
+ else
+ v = version;
- if (old_version)
- return;
-
- /* Skip epoch */
- v = strchr(new_version, ':');
- if (v != NULL)
- v = v + 1;
- else
- v = new_version;
+ snprintf(file, sizeof file, "%s-%s.%s.rpm", name, v, arch);
- snprintf(url, sizeof url,
- "%s/Packages/%s-%s.%s.rpm", yum_url, name, v, arch);
- snprintf(file, sizeof file,
- "rpms/%s-%s.%s.rpm", name, v, arch);
- if (download_if_missing(url, file) < 0)
- (*errors)++;
+ return file;
}
-static void
-install_package(const char *name,
- const char *old_version,
- const char *new_version,
- const char *arch,
- void *data)
+static int
+download_packages(struct razor_set *system, struct razor_set *next)
{
- const char *v, *root = data;
- char file[PATH_MAX];
- struct razor_rpm *rpm;
-
- if (old_version) {
- printf("removing %s %s not handled\n", name, old_version);
- return;
+ struct razor_package_iterator *pi;
+ struct razor_package *package;
+ const char *name, *version, *arch;
+ char file[PATH_MAX], url[256];
+ int errors;
+
+ pi = razor_set_create_install_iterator(system, next);
+ errors = 0;
+ while (razor_package_iterator_next(pi, &package,
+ &name, &version, &arch)) {
+ snprintf(url, sizeof url,
+ "%s/Packages/%s",
+ yum_url, rpm_filename(name, version, arch));
+ snprintf(file, sizeof file,
+ "rpms/%s", rpm_filename(name, version, arch));
+ if (download_if_missing(url, file) < 0)
+ errors++;
}
+ razor_package_iterator_destroy(pi);
- /* Skip epoch */
- v = strchr(new_version, ':');
- if (v != NULL)
- v = v + 1;
- else
- v = new_version;
+ if (errors > 0) {
+ fprintf(stderr, "failed to download %d packages\n", errors);
+ return -1;
+ }
- printf("install %s %s\n", name, v);
- snprintf(file, sizeof file, "rpms/%s-%s.%s.rpm", name, v, arch);
+ return 0;
+}
- rpm = razor_rpm_open(file);
- if (rpm == NULL) {
- fprintf(stderr, "failed to open rpm %s\n", file);
- return;
- }
- if (razor_rpm_install(rpm, root) < 0) {
- fprintf(stderr,
- "failed to install rpm %s\n", file);
- return;
+static int
+install_packages(struct razor_set *system, struct razor_set *next)
+{
+ struct razor_package_iterator *pi;
+ struct razor_package *package;
+ struct razor_rpm *rpm;
+ const char *name, *version, *arch;
+ char file[PATH_MAX];
+
+ pi = razor_set_create_install_iterator(system, next);
+ while (razor_package_iterator_next(pi, &package,
+ &name, &version, &arch)) {
+ printf("install %s-%s\n", name, version);
+
+ 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);
+ return -1;
+ }
+ if (razor_rpm_install(rpm, install_root) < 0) {
+ fprintf(stderr,
+ "failed to install rpm %s\n", file);
+ return -1;
+ }
+ razor_rpm_close(rpm);
}
- razor_rpm_close(rpm);
+ razor_package_iterator_destroy(pi);
+
+ return 0;
}
static int
command_install(int argc, const char *argv[])
{
struct razor_root *root;
- struct razor_set *upstream, *next;
+ struct razor_set *system, *upstream, *next;
struct razor_transaction *trans;
int i = 0, errors, dependencies = 1;
@@ -660,9 +680,13 @@ command_install(int argc, const char *argv[])
i++;
}
- root = razor_root_open(install_root, RAZOR_ROOT_OPEN_WRITE);
+ root = razor_root_open(install_root);
+ if (root == NULL)
+ return 1;
+
+ system = razor_root_get_system_set(root);
upstream = razor_set_open(rawhide_repo_filename);
- trans = razor_root_create_transaction(root, upstream);
+ trans = razor_transaction_create(system, upstream);
for (; i < argc; i++) {
if (mark_packages_for_update(trans, upstream, argv[i]) == 0) {
@@ -690,17 +714,12 @@ command_install(int argc, const char *argv[])
return 1;
}
- errors = 0;
- razor_root_diff(root, download_package, &errors);
- if (errors > 0) {
- fprintf(stderr, "failed to download %d packages\n", errors);
+ if (download_packages(system, next) < 0) {
razor_root_close(root);
return 1;
}
- /* FIXME: We need to figure out the right install order here,
- * so the post and pre scripts can run. */
- razor_root_diff(root, install_package, (void *) install_root);
+ install_packages(system, next);
razor_set_destroy(next);
razor_set_destroy(upstream);
diff --git a/src/rpm.c b/src/rpm.c
index 7ad0d6d..e450bf1 100644
--- a/src/rpm.c
+++ b/src/rpm.c
@@ -414,7 +414,7 @@ create_set_from_command_line(int argc, const char *argv[])
struct razor_rpm *rpm;
int i;
- importer = razor_importer_new();
+ importer = razor_importer_create();
for (i = 0; i < argc; i++) {
rpm = razor_rpm_open(argv[i]);
@@ -507,12 +507,17 @@ command_verify(int argc, const char *argv[])
}
static void
-remove_package(const char *name,
- const char *old_version, const char *new_version,
- const char *arch, void *data)
+update_package(enum razor_diff_action action,
+ struct razor_package *package,
+ const char *name,
+ const char *version,
+ const char *arch,
+ void *data)
{
- if (old_version)
- printf("remove %s-%s.%s\n", name, old_version, arch);
+ if (action == RAZOR_DIFF_ACTION_ADD)
+ printf("install %s-%s.%s\n", name, version, arch);
+ if (action == RAZOR_DIFF_ACTION_REMOVE)
+ printf("remove %s-%s.%s\n", name, version, arch);
}
static void
@@ -555,7 +560,7 @@ command_erase(int argc, const char *argv[])
next = razor_transaction_finish(trans);
if (!option_justdb)
- razor_set_diff(set, next, remove_package, NULL);
+ razor_set_diff(set, next, update_package, NULL);
razor_set_destroy(set);
razor_set_destroy(upstream);
@@ -564,15 +569,6 @@ command_erase(int argc, const char *argv[])
}
static void
-install_package(const char *name,
- const char *old_version, const char *new_version,
- const char *arch, void *data)
-{
- if (new_version)
- printf("install %s-%s.%s\n", name, new_version, arch);
-}
-
-static void
command_install(int argc, const char *argv[])
{
struct razor_set *set, *upstream, *next;
@@ -608,7 +604,7 @@ command_install(int argc, const char *argv[])
next = razor_transaction_finish(trans);
if (!option_justdb)
- razor_set_diff(set, next, install_package, NULL);
+ razor_set_diff(set, next, update_package, NULL);
razor_set_destroy(set);
razor_set_destroy(upstream);
@@ -617,17 +613,6 @@ command_install(int argc, const char *argv[])
}
static void
-update_package(const char *name,
- const char *old_version, const char *new_version,
- const char *arch, void *data)
-{
- if (old_version)
- printf("remove %s-%s.%s\n", name, old_version, arch);
- if (new_version)
- printf("install %s-%s.%s\n", name, new_version, arch);
-}
-
-static void
command_update(int argc, const char *argv[])
{
struct razor_set *set, *upstream, *next;