Changeset 4849


Ignore:
Timestamp:
12/05/08 04:37:48 (5 years ago)
Author:
tick
Message:

adding list_upgradable

opkg: refactory the upgradable list

Location:
trunk/src/target/opkg/libopkg
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/opkg/libopkg/args.c

    r4818 r4849  
    268268     printf("\tlist             List available packages and descriptions\n"); 
    269269     printf("\tlist_installed           List all and only the installed packages and description \n"); 
     270     printf("\tlist_upgradable          List all the installed and upgradable packages\n"); 
    270271     printf("\tfiles <pkg>              List all files belonging to <pkg>\n"); 
    271272     printf("\tsearch <file|regexp>             Search for a package providing <file>\n"); 
  • trunk/src/target/opkg/libopkg/opkg.c

    r4838 r4849  
    930930opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data) 
    931931{ 
    932   pkg_vec_t *all; 
    933   int i; 
    934  
    935   opkg_assert (opkg); 
    936   opkg_assert (callback); 
    937  
    938   /* ensure all data is valid */ 
    939   pkg_info_preinstall_check (opkg->conf); 
    940  
    941   all = pkg_vec_alloc (); 
    942   pkg_hash_fetch_available (&opkg->conf->pkg_hash, all); 
    943   for (i = 0; i < all->len; i++) 
    944   { 
    945     pkg_t *old, *new; 
    946     int cmp; 
    947     opkg_package_t *package; 
    948  
    949     old = all->pkgs[i]; 
    950      
    951     if (old->state_status != SS_INSTALLED) 
    952       continue; 
    953  
    954     new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, old->name, NULL); 
    955     if (new == NULL) { 
    956       /* XXX: Notice: Assuming locally install package is up to date */ 
    957       continue; 
    958     } 
    959            
    960     cmp = pkg_compare_versions(old, new); 
    961  
    962     if (cmp < 0) 
    963     { 
    964       package = old_pkg_to_new (new); 
    965       callback (opkg, package, user_data); 
    966       opkg_package_free (package); 
    967     } 
    968   } 
    969  
    970   pkg_vec_free (all); 
    971  
    972   return 0; 
     932    pkg_vec_t *all; 
     933    int i; 
     934 
     935    opkg_assert (opkg); 
     936    opkg_assert (callback); 
     937 
     938    /* ensure all data is valid */ 
     939    pkg_info_preinstall_check (opkg->conf); 
     940 
     941    all = opkg_upgrade_all_list_get (opkg->conf); 
     942    for (i = 0; i < all->len; i++) 
     943    { 
     944        pkg_t *old, *new; 
     945        opkg_package_t *package; 
     946 
     947        old = all->pkgs[i]; 
     948 
     949        new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, old->name, NULL); 
     950 
     951        package = old_pkg_to_new (new); 
     952        callback (opkg, package, user_data); 
     953        opkg_package_free (package); 
     954    } 
     955 
     956    pkg_vec_free (all); 
     957 
     958    return 0; 
    973959} 
    974960 
  • trunk/src/target/opkg/libopkg/opkg_cmd.c

    r4844 r4849  
    5656static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv); 
    5757static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv); 
     58static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv); 
    5859static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv); 
    5960static int opkg_purge_cmd(opkg_conf_t *conf, int argc, char **argv); 
     
    8283     {"list", 0, (opkg_cmd_fun_t)opkg_list_cmd}, 
    8384     {"list_installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd}, 
     85     {"list_upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd}, 
    8486     {"info", 0, (opkg_cmd_fun_t)opkg_info_cmd}, 
    8587     {"flag", 1, (opkg_cmd_fun_t)opkg_flag_cmd}, 
     
    781783 
    782784     return 0; 
     785} 
     786 
     787static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv)  
     788{ 
     789    pkg_vec_t *all = opkg_upgrade_all_list_get(conf); 
     790    pkg_t *_old_pkg, *_new_pkg; 
     791    char *old_v, *new_v; 
     792    int i; 
     793    for (i=0;i<all->len;i++) { 
     794        _old_pkg = all->pkgs[i]; 
     795        _new_pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, _old_pkg->name, NULL); 
     796        old_v = pkg_version_str_alloc(_old_pkg); 
     797        new_v = pkg_version_str_alloc(_new_pkg); 
     798        if (opkg_cb_list) 
     799            opkg_cb_list(_old_pkg->name, new_v, old_v, _old_pkg->state_status, p_userdata); 
     800        free(old_v); 
     801        free(new_v); 
     802    } 
     803    pkg_vec_free(all); 
     804    return 0; 
    783805} 
    784806 
  • trunk/src/target/opkg/libopkg/opkg_upgrade.c

    r4847 r4849  
    7878    return opkg_install_pkg(conf, new,1); 
    7979} 
     80 
     81 
     82 
     83pkg_vec_t *opkg_upgrade_all_list_get(opkg_conf_t *conf) { 
     84    pkg_vec_t *all, *ans; 
     85    int i; 
     86 
     87    /* ensure all data is valid */ 
     88    pkg_info_preinstall_check (conf); 
     89 
     90    all = pkg_vec_alloc (); 
     91    ans = pkg_vec_alloc (); 
     92    pkg_hash_fetch_all_installed (&conf->pkg_hash, all); 
     93    for (i = 0; i < all->len; i++) 
     94    { 
     95        pkg_t *old, *new; 
     96        int cmp; 
     97 
     98        old = all->pkgs[i]; 
     99        new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name, NULL); 
     100 
     101        if (new == NULL) 
     102            continue; 
     103 
     104        cmp = pkg_compare_versions(old, new); 
     105 
     106        if ( cmp < 0 ) 
     107            pkg_vec_insert(ans, old); 
     108    } 
     109    pkg_vec_free (all); 
     110    return ans; 
     111} 
  • trunk/src/target/opkg/libopkg/opkg_upgrade.h

    r4357 r4849  
    1515 
    1616int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old); 
     17pkg_vec_t *opkg_upgrade_all_list_get(opkg_conf_t *conf); 
  • trunk/src/target/opkg/libopkg/pkg_vec.h

    r4357 r4849  
    4343void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg); 
    4444 
    45 void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg); 
    4645/* pkg_vec_insert_merge: might munge pkg. 
    4746*  returns the pkg that is in the pkg graph */ 
Note: See TracChangeset for help on using the changeset viewer.