- pkg_vec_free(available);
- } else {
- pkg_vec_t *installed_pkgs = pkg_vec_alloc();
- int i;
- int flagged_pkg_count = 0;
- int removed;
-
- pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
-
- for (i = 0; i < installed_pkgs->len; i++) {
- pkg_t *pkg = installed_pkgs->pkgs[i];
- if (pkg->state_flag & SF_USER) {
- flagged_pkg_count++;
- } else {
- if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL))
- opkg_message(conf, OPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
- }
- }
- if (!flagged_pkg_count) {
- opkg_message(conf, OPKG_NOTICE, "No packages flagged as installed by user, \n"
- "so refusing to uninstall unflagged non-leaf packages\n");
- return 0;
- }
-
- /* find packages not flagged SF_USER (i.e., installed to
- * satisfy a dependence) and not having any dependents, and
- * remove them */
- do {
- removed = 0;
- for (i = 0; i < installed_pkgs->len; i++) {
- pkg_t *pkg = installed_pkgs->pkgs[i];
- if (!(pkg->state_flag & SF_USER)
- && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) {
- removed++;
- opkg_message(conf, OPKG_NOTICE, "Removing non-user leaf package %s\n");
- opkg_remove_pkg(conf, pkg,0);
- done = 1;
- }
- }
- } while (removed);
- pkg_vec_free(installed_pkgs);