summaryrefslogtreecommitdiffstats
path: root/libopkg/opkg_remove.c
diff options
context:
space:
mode:
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-14 23:51:23 (EST)
committer ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-14 23:51:23 (EST)
commit16f37e3866a32ffd42e8e00414d10f8a934dec14 (patch)
tree9897cf3e10b2c55a33ca0d4ed45fcfb9b3ba0506 /libopkg/opkg_remove.c
parent46d22486379f050eab3fd9a8f850875162c5d65e (diff)
opkg: implement removal of auto-installed packages
git-svn-id: http://opkg.googlecode.com/svn/trunk@39 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg/opkg_remove.c')
-rw-r--r--libopkg/opkg_remove.c65
1 files changed, 62 insertions, 3 deletions
diff --git a/libopkg/opkg_remove.c b/libopkg/opkg_remove.c
index 8bf1d2a..1a84e95 100644
--- a/libopkg/opkg_remove.c
+++ b/libopkg/opkg_remove.c
@@ -161,6 +161,61 @@ static int user_prefers_removing_dependents(opkg_conf_t *conf, abstract_pkg_t *a
return 0;
}
+static int remove_autoinstalled (opkg_conf_t *conf, pkg_t *pkg)
+{
+ /*
+ * find and remove packages that were autoinstalled and are orphaned by the removal of pkg
+ */
+
+ char *buffer, *d_str;
+ int i;
+
+ for (i = 0; i < pkg->depends_count; ++i)
+ {
+ int x = 0;
+ pkg_t *p;
+ d_str = pkg->depends_str[i];
+ buffer = malloc (strlen (d_str) + 1);
+ if (!buffer)
+ {
+ fprintf(stderr,"%s Unable to allocate memory.\n", __FUNCTION__);
+ return -1;
+ }
+
+ while (d_str[x] != '\0' && d_str[x] != ' ')
+ {
+ buffer[x] = d_str[x];
+ ++x;
+ }
+ buffer[x] = '\0';
+ buffer = realloc (buffer, strlen (buffer) + 1);
+ p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash, buffer);
+
+ /* if the package is not installed, this could have been a circular
+ * depenancy and the package has already been removed */
+ if (!p)
+ return -1;
+
+ if (p->auto_installed)
+ {
+ int deps;
+ abstract_pkg_t **dependents;
+
+ deps = pkg_has_installed_dependents(conf, NULL, p, &dependents);
+ if (deps == 0)
+ {
+ printf ("%s was autoinstalled but is now orphaned\n", buffer);
+ opkg_remove_pkg(conf, p,0);
+ }
+ else
+ printf ("%s was autoinstalled and is still required by %d installed packages\n", buffer, deps);
+ }
+ free (buffer);
+ }
+
+ return 0;
+}
+
int opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg,int message)
{
/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
@@ -170,9 +225,6 @@ int opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg,int message)
int err;
abstract_pkg_t *parent_pkg = NULL;
- if (conf->autoremove)
- printf ("autoremove is enabled, but not yet implemented\n");
-
if (pkg->essential && !message) {
if (conf->force_removal_of_essential_packages) {
fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
@@ -252,6 +304,13 @@ int opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg,int message)
if (parent_pkg)
parent_pkg->state_status = SS_NOT_INSTALLED;
+
+ /* remove autoinstalled packages that are orphaned by the removal of this one */
+ if (conf->autoremove)
+ remove_autoinstalled (conf, pkg);
+
+
+
return 0;
}