Send commitlog mailing list submissions to
        commitlog@lists.openmoko.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.openmoko.org/mailman/listinfo/commitlog
or, via email, send a message with subject or body 'help' to
        [EMAIL PROTECTED]

You can reach the person managing the list at
        [EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of commitlog digest..."
Today's Topics:

   1. r4410 - in trunk/src/target/opkg: libopkg tests
      ([EMAIL PROTECTED])
--- Begin Message ---
Author: thomas
Date: 2008-04-30 11:07:15 +0200 (Wed, 30 Apr 2008)
New Revision: 4410

Modified:
   trunk/src/target/opkg/libopkg/opkg.c
   trunk/src/target/opkg/libopkg/opkg.h
   trunk/src/target/opkg/tests/libopkg_test.c
Log:
opkg: implement opkg_list_upgradable_packages function


Modified: trunk/src/target/opkg/libopkg/opkg.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.c        2008-04-29 20:52:55 UTC (rev 
4409)
+++ trunk/src/target/opkg/libopkg/opkg.c        2008-04-30 09:07:15 UTC (rev 
4410)
@@ -194,7 +194,7 @@
 }
 
 int
-opkg_read_config_files (opkg_t *opkg)
+opkg_re_read_config_files (opkg_t *opkg)
 {
   args_t *a;
   opkg_conf_t *c;
@@ -734,3 +734,53 @@
   return 0;
 }
 
+int
+opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, 
void *user_data)
+{
+  pkg_vec_t *all;
+  int i;
+
+  opkg_assert (opkg);
+  opkg_assert (callback);
+
+  all = pkg_vec_alloc ();
+  pkg_hash_fetch_available (&opkg->conf->pkg_hash, all);
+  for (i = 0; i < all->len; i++)
+  {
+    pkg_t *old, *new;
+    int cmp;
+    opkg_package_t *package;
+
+    old = all->pkgs[i];
+    
+    if (old->state_status != SS_INSTALLED)
+      continue;
+
+    new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, 
old->name);
+    if (new == NULL) {
+      /* XXX: Notice: Assuming locally install package is up to date */
+      continue;
+    }
+          
+    cmp = pkg_compare_versions(old, new);
+
+    if (cmp < 0)
+    {
+
+      package = opkg_package_new_with_values (
+          old->name,
+          old->version,
+          old->architecture,
+          old->description,
+          old->tags,
+          (old->state_status == SS_INSTALLED));
+
+      callback (opkg, package, user_data);
+    }
+  }
+
+  pkg_vec_free (all);
+
+  return 0;
+}
+

Modified: trunk/src/target/opkg/libopkg/opkg.h
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.h        2008-04-29 20:52:55 UTC (rev 
4409)
+++ trunk/src/target/opkg/libopkg/opkg.h        2008-04-30 09:07:15 UTC (rev 
4410)
@@ -41,7 +41,7 @@
 void opkg_free (opkg_t *opkg);
 void opkg_get_option (opkg_t *opkg, char *option, void **value);
 void opkg_set_option (opkg_t *opkg, char *option, void *value);
-int opkg_read_config_files (opkg_t *opkg);
+int opkg_re_read_config_files (opkg_t *opkg);
 
 int opkg_install_package (opkg_t *opkg, const char *package_name, 
opkg_progress_callback_t callback, void *user_data);
 int opkg_remove_package (opkg_t *opkg, const char *package_name, 
opkg_progress_callback_t callback, void *user_data);
@@ -50,3 +50,4 @@
 int opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t 
callback, void *user_data);
 
 int opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void 
*user_data);
+int opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t 
callback, void *user_data);

Modified: trunk/src/target/opkg/tests/libopkg_test.c
===================================================================
--- trunk/src/target/opkg/tests/libopkg_test.c  2008-04-29 20:52:55 UTC (rev 
4409)
+++ trunk/src/target/opkg/tests/libopkg_test.c  2008-04-30 09:07:15 UTC (rev 
4410)
@@ -26,6 +26,12 @@
   opkg_package_free (pkg);
 }
 
+void
+package_list_upgradable_callback (opkg_t *opkg, opkg_package_t *pkg, void 
*data)
+{
+  printf ("%s - %s\n", pkg->name, pkg->version);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -36,7 +42,7 @@
 
   opkg_set_option (opkg, "offline_root", "/tmp/");
 
-  opkg_read_config_files (opkg);
+  opkg_re_read_config_files (opkg);
 
   err = opkg_update_package_lists (opkg, progress_callback, "Updating...");
   printf ("\nopkg_update_package_lists returned %d\n", err);
@@ -47,12 +53,15 @@
   err = opkg_upgrade_package (opkg, "aspell", progress_callback, 
"Upgrading...");
   printf ("\nopkg_upgrade_package returned %d\n", err);
 
-  err = opkg_upgrade_all (opkg, progress_callback, "Upgrading all...");
-  printf ("\nopkg_upgrade_package returned %d\n", err);
-
   err = opkg_remove_package (opkg, "aspell", progress_callback, "Removing...");
   printf ("\nopkg_remove_package returned %d\n", err);
 
+  printf ("Listing upgradable packages...\n");
+  opkg_list_upgradable_packages (opkg, package_list_upgradable_callback, NULL);
+
+  err = opkg_upgrade_all (opkg, progress_callback, "Upgrading all...");
+  printf ("\nopkg_upgrade_all returned %d\n", err);
+
   opkg_list_packages (opkg, package_list_callback, NULL);
   printf ("\n");
 




--- End Message ---
_______________________________________________
commitlog mailing list
commitlog@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/commitlog

Reply via email to