Preconditions/Environment ------------------------- Triggering Action/Cause ----------------------- Build opkg with an external solver enabled. Try using the list upgradable command. Expectation ----------- A list of upgradable packages should be returned Actual Result ------------- A message is printed saying that the list upgradable command does not work with an external solver. Reproducibility --------------- 1/1 opkg_list_upgradable_cmd() uses a function from opkg_upgrade.c to list what packages are available for upgrading. This function is not built when an external solver is used since the solver should handle what can be upgraded. Because the solver decides what to upgrade, perhaps this listing should be handled by the solver as well. See todo in opkg_list_upgradable_cmd() in opkg_cmd.c
Created attachment 4030 [details] Patch to print transaction "list-upgradable" when using libsolv This works for me, altough it produces an output slightly different from the non-libsolv-enabled opkg build. It also prints dependencies that are newly installed or removed, like: packagename - not_installed - new_version packagename - old_version - removed "not_installed" and "removed" are printed as literals for such cases.
Comment on attachment 4030 [details] Patch to print transaction "list-upgradable" when using libsolv >diff -durpN opkg-0.3.5-bz2.orig/libopkg/opkg_cmd.c opkg-0.3.5-bz2/libopkg/opkg_cmd.c >--- opkg-0.3.5-bz2.orig/libopkg/opkg_cmd.c 2017-06-15 19:00:20.000000000 +0200 >+++ opkg-0.3.5-bz2/libopkg/opkg_cmd.c 2017-09-25 10:23:40.099784704 +0200 >@@ -616,11 +616,15 @@ static int opkg_list_changed_conffiles_c > static int opkg_list_upgradable_cmd(int argc, char **argv) > { > #ifndef HAVE_SOLVER_INTERNAL >- // TODO: this requires prepare_upgrade_list in opkg_upgrade.c but opkg_upgrade >- // is not built when an external solver is enabled. Either let the solver >- // handle this, include opkg_upgrade, or put prepare_upgrade_list somewhere else. >- opkg_msg(ERROR,"list-upgradable command not available with external solver enabled\n"); >- return -1; >+ int err = 0; >+ >+ signal(SIGINT, sigint_handler); the sigint_handler is used to write to the opkg database in case the operation is interrupted. Since list-upgradable it's not going to touch the opkg status file, you can omit the signal callback registration. >+ >+ pkg_info_preinstall_check(); >+ >+ err = opkg_solver_list_upgradable(argc, argv); >+ >+ return err; > #else I think we can follow the opkg_solver_{install,remove,upgrade} pattern and move this code to a opkg_solver_list_upgradable implementation for the internal solver on solver/internal/opkg_action.c > pkg_t *_old_pkg, *_new_pkg; > LIST_HEAD(head); >diff -durpN opkg-0.3.5-bz2.orig/libopkg/opkg_solver.h opkg-0.3.5-bz2/libopkg/opkg_solver.h >--- opkg-0.3.5-bz2.orig/libopkg/opkg_solver.h 2017-06-15 19:00:20.000000000 +0200 >+++ opkg-0.3.5-bz2/libopkg/opkg_solver.h 2017-09-25 10:22:25.931016465 +0200 >@@ -27,6 +27,7 @@ int opkg_solver_install(int num_pkgs, ch > int opkg_solver_remove(int num_pkgs, char **pkg_names); > int opkg_solver_upgrade(int num_pkgs, char **pkg_names); > int opkg_solver_distupgrade(int num_pkgs, char **pkg_names); >+int opkg_solver_list_upgradable(int num_pkgs, char **pkg_names); > > #ifdef __cplusplus > } >diff -durpN opkg-0.3.5-bz2.orig/libopkg/solvers/libsolv/opkg_solver_libsolv.c opkg-0.3.5-bz2/libopkg/solvers/libsolv/opkg_solver_libsolv.c >--- opkg-0.3.5-bz2.orig/libopkg/solvers/libsolv/opkg_solver_libsolv.c 2017-06-15 19:00:20.000000000 +0200 >+++ opkg-0.3.5-bz2/libopkg/solvers/libsolv/opkg_solver_libsolv.c 2017-09-25 10:26:51.531767555 +0200 >@@ -78,6 +78,7 @@ static void libsolv_solver_add_job(libso > version_constraint_t constraint); > static int libsolv_solver_solve(libsolv_solver_t *libsolv_solver); > static int libsolv_solver_execute_transaction(libsolv_solver_t *libsolv_solver); >+static int libsolv_solver_list_upgradable(libsolv_solver_t *libsolv_solver); > > int opkg_solver_install(int num_pkgs, char **pkg_names) > { >@@ -190,6 +191,38 @@ CLEANUP: > return err; > } > >+int opkg_solver_list_upgradable(int num_pkgs, char **pkg_names) >+{ >+ int i, err; >+ Dataiterator di; >+ >+ libsolv_solver_t *solver = libsolv_solver_new(); >+ if (solver == NULL) >+ return -1; >+ >+ if (num_pkgs == 0) { >+ libsolv_solver_add_job(solver, JOB_UPGRADE, 0, NULL, NONE); >+ } else { >+ for (i = 0; i < num_pkgs; i++) { >+ dataiterator_init(&di, solver->pool, solver->repo_installed, 0, 0, pkg_names[i], SEARCH_GLOB); >+ while (dataiterator_step(&di)) { >+ libsolv_solver_add_job(solver, JOB_UPGRADE, di.kv.str, NULL, NONE); >+ dataiterator_skip_solvable(&di); >+ } >+ dataiterator_free(&di); >+ } >+ } >+ >+ err = libsolv_solver_solve(solver); >+ if (err) >+ goto CLEANUP; >+ seems like all this code is the same as the on in opkg_solver_upgrade, maybe you could factor that out into a static function? >+ err = libsolv_solver_list_upgradable(solver); >+ >+CLEANUP: >+ libsolv_solver_free(solver); >+ return err; >+} > > int opkg_solver_distupgrade(int num_pkgs, char **pkg_names) > { >@@ -917,6 +950,76 @@ CLEANUP: > return err; > } > >+static int libsolv_solver_list_upgradable(libsolv_solver_t *libsolv_solver) >+{ >+ int i; >+ Transaction *transaction; >+ pkg_vec_t *pkgs; >+ >+ transaction = solver_create_transaction(libsolv_solver->solver); >+ pkgs = pkg_vec_alloc(); >+ >+ if (transaction->steps.count) { >+ pkg_t *pkg; >+ >+ /* order the transaction so dependencies are handled first */ >+ transaction_order(transaction, 0); >+ >+ for (i = 0; i < transaction->steps.count; i++) { >+ Id stepId = transaction->steps.elements[i]; >+ Solvable *solvable = pool_id2solvable(libsolv_solver->pool, stepId); >+ >+ const char *pkg_name = pool_id2str(libsolv_solver->pool, solvable->name); >+ const char *evr = pool_id2str(libsolv_solver->pool, solvable->evr); >+ >+ pkg = pkg_hash_fetch_by_name_version(pkg_name, evr); >+ pkg_vec_insert(pkgs, pkg); >+ } >+ >+ for (i = 0; i < transaction->steps.count; i++) { >+ Id stepId = transaction->steps.elements[i]; >+ Id typeId = transaction_type(transaction, stepId, >+ SOLVER_TRANSACTION_SHOW_ACTIVE | >+ SOLVER_TRANSACTION_CHANGE_IS_REINSTALL); >+ >+ pkg = pkgs->pkgs[i]; >+ pkg_t *old = 0; >+ char *old_v, *new_v; >+ >+ switch (typeId) { >+ case SOLVER_TRANSACTION_ERASE: >+ new_v = pkg_version_str_alloc(pkg); >+ printf("%s - %s - removed\n", pkg->name, new_v); >+ free(new_v); >+ break; while I do appreciate (and like) the more verbose output, I think this may break existing applications that may rely on an output that only gives a list of the packages that can be updated. This more verbose output sounds more like what you would get with a dry run (opkg --noaction upgrade) >+ case SOLVER_TRANSACTION_REINSTALL: >+ case SOLVER_TRANSACTION_INSTALL: >+ case SOLVER_TRANSACTION_MULTIINSTALL: >+ new_v = pkg_version_str_alloc(pkg); >+ printf("%s - not_installed - %s\n", pkg->name, new_v); >+ free(new_v); >+ break; >+ case SOLVER_TRANSACTION_DOWNGRADE: >+ case SOLVER_TRANSACTION_UPGRADE: This code is almost the same as the one in libsolv_solver_execute_transaction, maybe we could call into the same function? or split the function in too so we can at least share everything but the bottom for loop? BTW, thank you so much for taking this on, it has been on my TODO for a while, but just haven't taken the time to do it. >+ old = pkg_hash_fetch_installed_by_name(pkg->name); >+ new_v = pkg_version_str_alloc(pkg); >+ old_v = pkg_version_str_alloc(old); >+ printf("%s - %s - %s\n", pkg->name, old_v, new_v); >+ free(new_v); >+ free(old_v); >+ break; >+ case SOLVER_TRANSACTION_IGNORE: >+ default: >+ break; >+ } >+ } >+ } >+ >+ pkg_vec_free(pkgs); >+ transaction_free(transaction); >+ return 0; >+} >+ > char *opkg_solver_version_alloc(void) > { > char *version;
The latest patch was sent to the mailing list at https://groups.google.com/forum/#!topic/opkg-devel/ZJf2csuv_Ms
Fixed by Zoltán Böszörményi on cc624806a6179c2d3d7b3eec4260e50ab0653c5d