summaryrefslogtreecommitdiffstats
path: root/libopkg
diff options
context:
space:
mode:
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-15 00:34:16 (EST)
committer ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-15 00:34:16 (EST)
commit3035a6a3bff45f668d53cd94fafd44870d401c6e (patch)
treeb441e5bcfc4549ae2fbbf7db061e3665ae48b0cf /libopkg
parent4ec6ca94f200ed52f2cc00ff740bae13d7fef6be (diff)
opkg: using active_list to list all the installed pkgs.
adding function that allows node move from one list to another git-svn-id: http://opkg.googlecode.com/svn/trunk@178 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg')
-rw-r--r--libopkg/active_list.c12
-rw-r--r--libopkg/active_list.h1
-rw-r--r--libopkg/opkg_upgrade.c32
3 files changed, 36 insertions, 9 deletions
diff --git a/libopkg/active_list.c b/libopkg/active_list.c
index e100101..861454e 100644
--- a/libopkg/active_list.c
+++ b/libopkg/active_list.c
@@ -73,6 +73,18 @@ struct active_list * active_list_prev(struct active_list *head, struct active_li
return prev;
}
+
+struct active_list *active_list_move_node(struct active_list *old_head, struct active_list *new_head, struct active_list *node) {
+ struct active_list *prev;
+ if (!old_head || !new_head || !node)
+ return NULL;
+ if (old_head == new_head)
+ return node;
+ prev = active_list_prev(old_head, node);
+ active_list_add(new_head, node);
+ return prev;
+}
+
static void list_head_clear (struct list_head *head) {
struct active_list *next;
struct list_head *n, *ptr;
diff --git a/libopkg/active_list.h b/libopkg/active_list.h
index 28e909a..3bedc2f 100644
--- a/libopkg/active_list.h
+++ b/libopkg/active_list.h
@@ -33,6 +33,7 @@ void active_list_init(struct active_list *ptr);
void active_list_clear(struct active_list *head);
void active_list_add_depend(struct active_list *node, struct active_list *depend);
void active_list_add(struct active_list *head, struct active_list *node);
+struct active_list *active_list_move_node(struct active_list *old_head, struct active_list *new_head, struct active_list *node);
struct active_list * active_list_next(struct active_list *head, struct active_list *ptr);
diff --git a/libopkg/opkg_upgrade.c b/libopkg/opkg_upgrade.c
index a837f32..0861dfe 100644
--- a/libopkg/opkg_upgrade.c
+++ b/libopkg/opkg_upgrade.c
@@ -78,22 +78,36 @@ int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old)
return opkg_install_pkg(conf, new,1);
}
+
+static void pkg_hash_check_installed_pkg_helper(const char *pkg_name, void *entry, void *data) {
+ struct active_list * head = (struct active_list *) data;
+ abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
+ pkg_vec_t *pkg_vec = ab_pkg->pkgs;
+ int j;
+ if (pkg_vec) {
+ for (j = 0; j < pkg_vec->len; j++) {
+ pkg_t *pkg = pkg_vec->pkgs[j];
+ if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
+ active_list_add(head, &pkg->list);
+ }
+ }
+ }
+}
+
struct active_list * prepare_upgrade_list (opkg_conf_t *conf) {
- pkg_vec_t *all;
struct active_list * head = active_list_head_new();
- int i;
+ struct active_list * all = active_list_head_new();
+ struct active_list *node=NULL;
/* ensure all data is valid */
pkg_info_preinstall_check (conf);
- all = pkg_vec_alloc ();
- pkg_hash_fetch_all_installed (&conf->pkg_hash, all);
- for (i = 0; i < all->len; i++)
- {
+ hash_table_foreach(&conf->pkg_hash, pkg_hash_check_installed_pkg_helper, all);
+ for (node=active_list_next(all,all); node; node = active_list_next(all, node)) {
pkg_t *old, *new;
int cmp;
- old = all->pkgs[i];
+ old = list_entry(node, pkg_t, list);
new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name, NULL);
if (new == NULL)
@@ -102,9 +116,9 @@ struct active_list * prepare_upgrade_list (opkg_conf_t *conf) {
cmp = pkg_compare_versions(old, new);
if ( cmp < 0 ) {
- active_list_add(head, &old->list);
+ node = active_list_move_node(all, head, &old->list);
}
}
- pkg_vec_free (all);
+ active_list_head_delete(all);
return head;
}