r4849 - trunk/src/target/opkg/libopkg

tick at docs.openmoko.org tick at docs.openmoko.org
Fri Dec 5 04:37:49 CET 2008


Author: tick
Date: 2008-12-05 04:37:48 +0100 (Fri, 05 Dec 2008)
New Revision: 4849

Modified:
   trunk/src/target/opkg/libopkg/args.c
   trunk/src/target/opkg/libopkg/opkg.c
   trunk/src/target/opkg/libopkg/opkg_cmd.c
   trunk/src/target/opkg/libopkg/opkg_upgrade.c
   trunk/src/target/opkg/libopkg/opkg_upgrade.h
   trunk/src/target/opkg/libopkg/pkg_vec.h
Log:
adding list_upgradable

opkg: refactory the upgradable list


Modified: trunk/src/target/opkg/libopkg/args.c
===================================================================
--- trunk/src/target/opkg/libopkg/args.c	2008-12-04 14:31:54 UTC (rev 4848)
+++ trunk/src/target/opkg/libopkg/args.c	2008-12-05 03:37:48 UTC (rev 4849)
@@ -267,6 +267,7 @@
      printf("\nInformational Commands:\n");
      printf("\tlist    		List available packages and descriptions\n");
      printf("\tlist_installed		List all and only the installed packages and description \n");
+     printf("\tlist_upgradable		List all the installed and upgradable packages\n");
      printf("\tfiles <pkg>		List all files belonging to <pkg>\n");
      printf("\tsearch <file|regexp>		Search for a package providing <file>\n");
      printf("\tinfo [pkg|regexp]		Display all info for <pkg>\n");

Modified: trunk/src/target/opkg/libopkg/opkg.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.c	2008-12-04 14:31:54 UTC (rev 4848)
+++ trunk/src/target/opkg/libopkg/opkg.c	2008-12-05 03:37:48 UTC (rev 4849)
@@ -929,47 +929,33 @@
 int
 opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data)
 {
-  pkg_vec_t *all;
-  int i;
+    pkg_vec_t *all;
+    int i;
 
-  opkg_assert (opkg);
-  opkg_assert (callback);
+    opkg_assert (opkg);
+    opkg_assert (callback);
 
-  /* ensure all data is valid */
-  pkg_info_preinstall_check (opkg->conf);
+    /* ensure all data is valid */
+    pkg_info_preinstall_check (opkg->conf);
 
-  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;
+    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];
-    
-    if (old->state_status != SS_INSTALLED)
-      continue;
+        old = all->pkgs[i];
 
-    new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, old->name, NULL);
-    if (new == NULL) {
-      /* XXX: Notice: Assuming locally install package is up to date */
-      continue;
-    }
-          
-    cmp = pkg_compare_versions(old, new);
+        new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, old->name, NULL);
 
-    if (cmp < 0)
-    {
-      package = old_pkg_to_new (new);
-      callback (opkg, package, user_data);
-      opkg_package_free (package);
+        package = old_pkg_to_new (new);
+        callback (opkg, package, user_data);
+        opkg_package_free (package);
     }
-  }
 
-  pkg_vec_free (all);
+    pkg_vec_free (all);
 
-  return 0;
+    return 0;
 }
 
 opkg_package_t*

Modified: trunk/src/target/opkg/libopkg/opkg_cmd.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_cmd.c	2008-12-04 14:31:54 UTC (rev 4848)
+++ trunk/src/target/opkg/libopkg/opkg_cmd.c	2008-12-05 03:37:48 UTC (rev 4849)
@@ -55,6 +55,7 @@
 static int opkg_install_pending_cmd(opkg_conf_t *conf, int argc, char **argv);
 static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv);
 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);
 static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv);
 static int opkg_purge_cmd(opkg_conf_t *conf, int argc, char **argv);
 static int opkg_flag_cmd(opkg_conf_t *conf, int argc, char **argv);
@@ -81,6 +82,7 @@
      {"upgrade", 0, (opkg_cmd_fun_t)opkg_upgrade_cmd},
      {"list", 0, (opkg_cmd_fun_t)opkg_list_cmd},
      {"list_installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd},
+     {"list_upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd},
      {"info", 0, (opkg_cmd_fun_t)opkg_info_cmd},
      {"flag", 1, (opkg_cmd_fun_t)opkg_flag_cmd},
      {"status", 0, (opkg_cmd_fun_t)opkg_status_cmd},
@@ -782,6 +784,26 @@
      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);
+    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];
+        _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);
+        if (opkg_cb_list)
+            opkg_cb_list(_old_pkg->name, new_v, old_v, _old_pkg->state_status, p_userdata);
+        free(old_v);
+        free(new_v);
+    }
+    pkg_vec_free(all);
+    return 0;
+}
+
 static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int installed_only)
 {
      int i;

Modified: trunk/src/target/opkg/libopkg/opkg_upgrade.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_upgrade.c	2008-12-04 14:31:54 UTC (rev 4848)
+++ trunk/src/target/opkg/libopkg/opkg_upgrade.c	2008-12-05 03:37:48 UTC (rev 4849)
@@ -77,3 +77,35 @@
     new->state_flag |= SF_USER;
     return opkg_install_pkg(conf, new,1);
 }
+
+
+
+pkg_vec_t *opkg_upgrade_all_list_get(opkg_conf_t *conf) {
+    pkg_vec_t *all, *ans;
+    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++)
+    {
+        pkg_t *old, *new;
+        int cmp;
+
+        old = all->pkgs[i];
+        new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name, NULL);
+
+        if (new == NULL)
+            continue;
+
+        cmp = pkg_compare_versions(old, new);
+
+        if ( cmp < 0 )
+            pkg_vec_insert(ans, old);
+    }
+    pkg_vec_free (all);
+    return ans;
+}

Modified: trunk/src/target/opkg/libopkg/opkg_upgrade.h
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_upgrade.h	2008-12-04 14:31:54 UTC (rev 4848)
+++ trunk/src/target/opkg/libopkg/opkg_upgrade.h	2008-12-05 03:37:48 UTC (rev 4849)
@@ -14,3 +14,4 @@
 */
 
 int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old);
+pkg_vec_t *opkg_upgrade_all_list_get(opkg_conf_t *conf);

Modified: trunk/src/target/opkg/libopkg/pkg_vec.h
===================================================================
--- trunk/src/target/opkg/libopkg/pkg_vec.h	2008-12-04 14:31:54 UTC (rev 4848)
+++ trunk/src/target/opkg/libopkg/pkg_vec.h	2008-12-05 03:37:48 UTC (rev 4849)
@@ -42,7 +42,6 @@
 void pkg_vec_free(pkg_vec_t *vec);
 void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
 
-void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
 /* pkg_vec_insert_merge: might munge pkg.
 *  returns the pkg that is in the pkg graph */
 pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, opkg_conf_t *conf);




More information about the commitlog mailing list