#include "active_list.h"
#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
void active_list_init(struct active_list *ptr) {
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);
+}
+
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);
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);
/* 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;
}
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);
free(old_v);
free(new_v);
}
- pkg_vec_free(all);
+ active_list_head_delete(head);
return 0;
}
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++)
{
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;
}
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