summaryrefslogtreecommitdiffstats
path: root/libopkg
diff options
context:
space:
mode:
Diffstat (limited to 'libopkg')
-rw-r--r--libopkg/active_list.c14
-rw-r--r--libopkg/active_list.h3
-rw-r--r--libopkg/opkg.c23
-rw-r--r--libopkg/opkg_cmd.c10
-rw-r--r--libopkg/opkg_upgrade.c15
-rw-r--r--libopkg/opkg_upgrade.h7
6 files changed, 44 insertions, 28 deletions
diff --git a/libopkg/active_list.c b/libopkg/active_list.c
index 08e1bd7..e100101 100644
--- a/libopkg/active_list.c
+++ b/libopkg/active_list.c
@@ -18,6 +18,8 @@
#include "active_list.h"
#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
void active_list_init(struct active_list *ptr) {
@@ -103,3 +105,15 @@ void active_list_add(struct active_list *head, struct active_list *node) {
list_add_tail(&node->node, &head->node);
node->depended = head;
}
+
+struct active_list * active_list_head_new() {
+ struct active_list * head = calloc(1, sizeof(struct active_list));
+ active_list_init(head);
+ return head;
+}
+
+void active_list_head_delete(struct active_list *head) {
+ active_list_clear(head);
+ free(head);
+}
+
diff --git a/libopkg/active_list.h b/libopkg/active_list.h
index 262164a..28e909a 100644
--- a/libopkg/active_list.h
+++ b/libopkg/active_list.h
@@ -26,6 +26,9 @@ struct active_list {
struct active_list *depended;
};
+
+struct active_list * active_list_head_new();
+void active_list_head_delete(struct active_list *);
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);
diff --git a/libopkg/opkg.c b/libopkg/opkg.c
index 857ed74..28e2c8c 100644
--- a/libopkg/opkg.c
+++ b/libopkg/opkg.c
@@ -940,8 +940,11 @@ opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_d
int
opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data)
{
- pkg_vec_t *all;
- int i;
+ struct active_list *head;
+ struct active_list *node;
+ pkg_t *old=NULL, *new = NULL;
+ static opkg_package_t* package=NULL;
+
opkg_assert (opkg);
opkg_assert (callback);
@@ -949,23 +952,15 @@ opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, v
/* ensure all data is valid */
pkg_info_preinstall_check (opkg->conf);
- all = opkg_upgrade_all_list_get (opkg->conf);
- for (i = 0; i < all->len; i++)
- {
- pkg_t *old, *new;
- opkg_package_t *package;
-
- old = all->pkgs[i];
-
+ head = prepare_upgrade_list(opkg->conf);
+ for (node=active_list_next(head, head); node; active_list_next(head,node)) {
+ old = list_entry(node, pkg_t, list);
new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, old->name, NULL);
-
package = pkg_clone (new);
callback (opkg, package, user_data);
opkg_package_free (package);
}
-
- pkg_vec_free (all);
-
+ active_list_head_delete(head);
return 0;
}
diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c
index 56649ea..2bb9372 100644
--- a/libopkg/opkg_cmd.c
+++ b/libopkg/opkg_cmd.c
@@ -786,12 +786,12 @@ static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv)
static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv)
{
- pkg_vec_t *all = opkg_upgrade_all_list_get(conf);
+ struct active_list *head = prepare_upgrade_list(conf);
+ struct active_list *node=NULL;
pkg_t *_old_pkg, *_new_pkg;
char *old_v, *new_v;
- int i;
- for (i=0;i<all->len;i++) {
- _old_pkg = all->pkgs[i];
+ for (node = active_list_next(head, head); node;node = active_list_next(head,node)) {
+ _old_pkg = list_entry(node, pkg_t, list);
_new_pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, _old_pkg->name, NULL);
old_v = pkg_version_str_alloc(_old_pkg);
new_v = pkg_version_str_alloc(_new_pkg);
@@ -800,7 +800,7 @@ static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv)
free(old_v);
free(new_v);
}
- pkg_vec_free(all);
+ active_list_head_delete(head);
return 0;
}
diff --git a/libopkg/opkg_upgrade.c b/libopkg/opkg_upgrade.c
index d014979..a837f32 100644
--- a/libopkg/opkg_upgrade.c
+++ b/libopkg/opkg_upgrade.c
@@ -78,17 +78,15 @@ int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old)
return opkg_install_pkg(conf, new,1);
}
-
-
-pkg_vec_t *opkg_upgrade_all_list_get(opkg_conf_t *conf) {
- pkg_vec_t *all, *ans;
+struct active_list * prepare_upgrade_list (opkg_conf_t *conf) {
+ pkg_vec_t *all;
+ struct active_list * head = active_list_head_new();
int i;
/* ensure all data is valid */
pkg_info_preinstall_check (conf);
all = pkg_vec_alloc ();
- ans = pkg_vec_alloc ();
pkg_hash_fetch_all_installed (&conf->pkg_hash, all);
for (i = 0; i < all->len; i++)
{
@@ -103,9 +101,10 @@ pkg_vec_t *opkg_upgrade_all_list_get(opkg_conf_t *conf) {
cmp = pkg_compare_versions(old, new);
- if ( cmp < 0 )
- pkg_vec_insert(ans, old);
+ if ( cmp < 0 ) {
+ active_list_add(head, &old->list);
+ }
}
pkg_vec_free (all);
- return ans;
+ return head;
}
diff --git a/libopkg/opkg_upgrade.h b/libopkg/opkg_upgrade.h
index 1523cee..ac4952d 100644
--- a/libopkg/opkg_upgrade.h
+++ b/libopkg/opkg_upgrade.h
@@ -12,6 +12,11 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/
+#ifndef OPKG_UPGRADE_H
+#define OPKG_UPGRADE_H
+#include "active_list.h"
int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old);
-pkg_vec_t *opkg_upgrade_all_list_get(opkg_conf_t *conf);
+struct active_list * prepare_upgrade_list (opkg_conf_t *conf);
+
+#endif