adding list_upgradable
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:31:22 +0000 (05:31 +0000)
committerticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:31:22 +0000 (05:31 +0000)
opkg: refactory the upgradable list

git-svn-id: http://opkg.googlecode.com/svn/trunk@164 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

libopkg/args.c
libopkg/opkg.c
libopkg/opkg_cmd.c
libopkg/opkg_upgrade.c
libopkg/opkg_upgrade.h
libopkg/pkg_vec.h

index d767bfbe9438de28cf5cbaa574667a3fdb5752b4..1f681c745c3045e7ba91a790ef3b38871834cbe3 100644 (file)
@@ -267,6 +267,7 @@ void args_usage(char *complaint)
      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");
index 35ddb89bcebee341774dc75aac8cce4e67e409cc..60475f31ffe9ef56c19c01e94a63a7b4269836bd 100644 (file)
@@ -929,47 +929,33 @@ 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;
+    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*
index 5b842bd4a37c5949a68cac8f922e40a23d4bf3d3..f5d78da6970fd2d77d89700324fba4762fc83083 100644 (file)
@@ -55,6 +55,7 @@ static int opkg_status_cmd(opkg_conf_t *conf, int argc, char **argv);
 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 @@ static opkg_cmd_t cmds[] = {
      {"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 @@ static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv)
      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;
index 925d9d8bbf5e3646dcafad217c9f165b8fbccf4a..d01497975aad7425ef5d437f1b6cfe16f51f931a 100644 (file)
@@ -77,3 +77,35 @@ int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old)
     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;
+}
index d8e4b6584fb3df44699a607e973bafb68fcb2e37..1523ceecc9973effdc8ca273bf9c68e32d2c4e6c 100644 (file)
@@ -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);
index a316c5008184a41da1c6bd8e2c75106d12141667..0ec74893ad1c5cd9e1f78e024f1eb3e510034e58 100644 (file)
@@ -42,7 +42,6 @@ pkg_vec_t * pkg_vec_alloc(void);
 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);