/** Private Functions ***/
+/**
+ * Clone a pkg_t
+ */
static opkg_package_t*
-old_pkg_to_new (pkg_t *old)
+pkg_t_to_opkg_package_t (pkg_t *old)
{
opkg_package_t *new;
new->tags = sstrdup (old->tags);
new->url = sstrdup (old->url);
+#undef sstrdup
+
new->size = (old->size) ? atoi (old->size) : 0;
new->installed = (old->state_status == SS_INSTALLED);
}
+/**
+ * @brief libopkg API: Install package
+ * @param opkg Then opkg handler
+ * @param package_name The name of package in which is going to install
+ * @param progress_callback The callback function that report the status to caller.
+ */
int
opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
{
new->state_flag |= SF_USER;
pdata.action = OPKG_INSTALL;
- pdata.package = old_pkg_to_new (new);
+ pdata.package = pkg_t_to_opkg_package_t (new);
progress (pdata, 0);
continue;
opkg_package_free (pdata.package);
- pdata.package = old_pkg_to_new (pkg);
+ pdata.package = pkg_t_to_opkg_package_t (pkg);
pdata.action = OPKG_DOWNLOAD;
if (pkg->src == NULL)
/* 75% of "install" progress is for downloading */
opkg_package_free (pdata.package);
- pdata.package = old_pkg_to_new (new);
+ pdata.package = pkg_t_to_opkg_package_t (new);
pdata.action = OPKG_INSTALL;
progress (pdata, 75);
}
pdata.action = OPKG_REMOVE;
- pdata.package = old_pkg_to_new (pkg);
+ pdata.package = pkg_t_to_opkg_package_t (pkg);
progress (pdata, 0);
}
pdata.action = OPKG_INSTALL;
- pdata.package = old_pkg_to_new (pkg);
+ pdata.package = pkg_t_to_opkg_package_t (pkg);
progress (pdata, 0);
err = opkg_upgrade_pkg (opkg->conf, pkg);
{
pkg = installed->pkgs[i];
- pdata.package = old_pkg_to_new (pkg);
+ pdata.package = pkg_t_to_opkg_package_t (pkg);
progress (pdata, 99 * i / installed->len);
opkg_package_free (pdata.package);
pkg = all->pkgs[i];
- package = old_pkg_to_new (pkg);
+ package = pkg_t_to_opkg_package_t (pkg);
callback (opkg, package, user_data);
opkg_package_free (package);
}
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 = old_pkg_to_new (new);
+ package = pkg_t_to_opkg_package_t (new);
callback (opkg, package, user_data);
opkg_package_free (package);
}
-
- pkg_vec_free (all);
-
+ active_list_head_delete(head);
return 0;
}
}
/* match found */
- package = old_pkg_to_new (pkg);
+ package = pkg_t_to_opkg_package_t (pkg);
break;
}