summaryrefslogtreecommitdiff
path: root/librazor
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2008-07-08 22:02:58 -0400
committerKristian Høgsberg <krh@redhat.com>2008-07-08 22:02:58 -0400
commit934988759a7ec9c7d58de3504846287fa25d94de (patch)
tree46dc17c4ddd8745fafb8bdb4dfc017d4832bcd2d /librazor
parent5e777955178cbb1eb37ca9c95ec9c04ff90be939 (diff)
Change the install iterator API to what we want.
Diffstat (limited to 'librazor')
-rw-r--r--librazor/razor.c108
-rw-r--r--librazor/razor.h21
2 files changed, 89 insertions, 40 deletions
diff --git a/librazor/razor.c b/librazor/razor.c
index 1a8dfda..4276381 100644
--- a/librazor/razor.c
+++ b/librazor/razor.c
@@ -739,60 +739,96 @@ razor_set_diff(struct razor_set *set, struct razor_set *upstream,
razor_package_iterator_destroy(pi2);
}
+struct install_action {
+ enum razor_install_action action;
+ struct razor_package *package;
+};
+
+struct razor_install_iterator {
+ struct razor_set *set;
+ struct razor_set *next;
+ struct array actions;
+ struct install_action *a, *end;
+};
+
static void
-add_new_package(enum razor_diff_action action,
- struct razor_package *package,
- const char *name,
- const char *version,
- const char *arch,
- void *data)
+add_action(enum razor_diff_action action,
+ struct razor_package *package,
+ const char *name,
+ const char *version,
+ const char *arch,
+ void *data)
{
- if (action == RAZOR_DIFF_ACTION_ADD)
- razor_package_query_add_package(data, package);
+ struct razor_install_iterator *ii = data;
+ struct install_action *a;
+
+ a = array_add(&ii->actions, sizeof *a);
+ a->package = package;
+
+ switch (action) {
+ case RAZOR_DIFF_ACTION_ADD:
+ a->action = RAZOR_INSTALL_ACTION_ADD;
+ break;
+ case RAZOR_DIFF_ACTION_REMOVE:
+ a->action = RAZOR_INSTALL_ACTION_REMOVE;
+ break;
+ }
}
-RAZOR_EXPORT struct razor_package_iterator *
-razor_set_create_remove_iterator(struct razor_set *set,
- struct razor_set *next)
+RAZOR_EXPORT struct razor_install_iterator *
+razor_set_create_install_iterator(struct razor_set *set,
+ struct razor_set *next)
{
- struct razor_package_query *query;
- struct razor_package_iterator *pi;
+ struct razor_install_iterator *ii;
assert (set != NULL);
assert (next != NULL);
- query = razor_package_query_create(set);
- razor_set_diff(next, set, add_new_package, query);
+ ii = zalloc(sizeof *ii);
+ ii->set = set;
+ ii->next = next;
+
+ razor_set_diff(set, next, add_action, ii);
- pi = razor_package_query_finish(query);
+ ii->a = ii->actions.data;
+ ii->end = ii->actions.data + ii->actions.size;
/* FIXME: We need to figure out the right install order here,
* so the post and pre scripts can run. */
- /* sort */
-
- return pi;
+ return ii;
}
-RAZOR_EXPORT struct razor_package_iterator *
-razor_set_create_install_iterator(struct razor_set *set,
- struct razor_set *next)
+RAZOR_EXPORT int
+razor_install_iterator_next(struct razor_install_iterator *ii,
+ struct razor_set **set,
+ struct razor_package **package,
+ enum razor_install_action *action,
+ int *count)
{
- struct razor_package_query *query;
- struct razor_package_iterator *pi;
-
- assert (set != NULL);
- assert (next != NULL);
-
- query = razor_package_query_create(next);
- razor_set_diff(set, next, add_new_package, query);
+ if (ii->a == ii->end)
+ return 0;
+
+ switch (ii->a->action) {
+ case RAZOR_INSTALL_ACTION_ADD:
+ *set = ii->next;
+ break;
+ case RAZOR_INSTALL_ACTION_REMOVE:
+ *set = ii->set;
+ break;
+ }
- pi = razor_package_query_finish(query);
+ *package = ii->a->package;
+ *action = ii->a->action;
+ *count = 0;
+ ii->a++;
- /* FIXME: We need to figure out the right install order here,
- * so the post and pre scripts can run. */
-
- /* sort */
+ return 1;
+}
- return pi;
+RAZOR_EXPORT void
+razor_install_iterator_destroy(struct razor_install_iterator *ii)
+{
+ array_release(&ii->actions);
+ free(ii);
}
diff --git a/librazor/razor.h b/librazor/razor.h
index 856a05f..51d05a7 100644
--- a/librazor/razor.h
+++ b/librazor/razor.h
@@ -191,13 +191,26 @@ typedef void (*razor_diff_callback_t)(enum razor_diff_action action,
void
razor_set_diff(struct razor_set *set, struct razor_set *upstream,
razor_diff_callback_t callback, void *data);
-struct razor_package_iterator *
-razor_set_create_remove_iterator(struct razor_set *set,
- struct razor_set *next);
-struct razor_package_iterator *
+
+struct razor_install_iterator;
+
+enum razor_install_action {
+ RAZOR_INSTALL_ACTION_ADD,
+ RAZOR_INSTALL_ACTION_REMOVE
+};
+
+struct razor_install_iterator *
razor_set_create_install_iterator(struct razor_set *set,
struct razor_set *next);
+int razor_install_iterator_next(struct razor_install_iterator *ii,
+ struct razor_set **set,
+ struct razor_package **package,
+ enum razor_install_action *action,
+ int *count);
+
+void razor_install_iterator_destroy(struct razor_install_iterator *ii);
+
/**
* SECTION:transaction
* @title: Transaction