Added support to list and remove orphaned packages.
A new target has been added to xbps-bin: autoremove. It works in the same way than 'apt-get', but there's no stdin input. By default it will list you all orphaned packages, and -f flag must be set to really remove them. The following is a real example for the git package, which requires directly perl and curl-libs, and indirectly libidn and openssl. $ xbps-bin -r ~/testing-xbps remove git Removing package git-1.6.1.3 ... done. $ $ xbps-bin -r ~/testing-xbps autoremove The following packages were installed automatically (as dependencies) and aren't needed anymore: perl-5.10.0 curl-libs-7.19.0 libidn-1.10 openssl-0.9.8j If you are really sure you don't need them, use -f to confirm. $ --HG-- extra : convert_revision : 70eebaa3d99be27753b94f580c8ec86330c7c2d3
This commit is contained in:
@@ -57,11 +57,12 @@ usage(void)
|
||||
" -v\t\t<verbose>\n"
|
||||
" Options used by the files target:\n"
|
||||
" -C\t\tTo check the SHA256 hash for any listed file.\n"
|
||||
" Options used by the remove target:\n"
|
||||
" Options used by the (auto)remove target:\n"
|
||||
" -f\t\tForce removal, even if package is required by other\n"
|
||||
" \t\tpackages that are currently installed.\n"
|
||||
"\n"
|
||||
" Examples:\n"
|
||||
" $ xbps-bin autoremove\n"
|
||||
" $ xbps-bin install klibc\n"
|
||||
" $ xbps-bin -r /path/to/root install klibc\n"
|
||||
" $ xbps-bin -C files klibc\n"
|
||||
@@ -142,10 +143,14 @@ int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
prop_array_t reqby;
|
||||
prop_array_t reqby, orphans;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
static size_t count;
|
||||
const char *pkgname, *version;
|
||||
char *plist, *root = NULL;
|
||||
int c, flags = 0, rv = 0;
|
||||
bool chkhash = false, forcerm = false;
|
||||
bool chkhash = false, forcerm = false, verbose = false;
|
||||
|
||||
while ((c = getopt(argc, argv, "Cfr:v")) != -1) {
|
||||
switch (c) {
|
||||
@@ -161,6 +166,7 @@ main(int argc, char **argv)
|
||||
xbps_set_rootdir(root);
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
flags |= XBPS_UNPACK_VERBOSE;
|
||||
break;
|
||||
case '?':
|
||||
@@ -234,34 +240,48 @@ main(int argc, char **argv)
|
||||
printf("Package %s is not installed.\n", argv[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
|
||||
|
||||
reqby = prop_dictionary_get(dict, "requiredby");
|
||||
if (reqby != NULL && prop_array_count(reqby) > 0) {
|
||||
printf("WARNING! %s is required by the following "
|
||||
"packages:\n", argv[1]);
|
||||
printf("WARNING! %s-%s is required by the following "
|
||||
"packages:\n", argv[1], version);
|
||||
(void)xbps_callback_array_iter_in_dict(dict,
|
||||
"requiredby", show_reqby_pkgs, NULL);
|
||||
prop_object_release(dict);
|
||||
if (!forcerm) {
|
||||
prop_object_release(dict);
|
||||
printf("\n\nIf you are sure about this, use "
|
||||
"-f to force deletion for this package.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
} else
|
||||
printf("\n\nForcing %s for deletion!\n",
|
||||
argv[1]);
|
||||
printf("\n\nForcing %s-%s for deletion!\n",
|
||||
argv[1], version);
|
||||
}
|
||||
|
||||
printf("Removing package %s-%s ... ", argv[1], version);
|
||||
if (verbose)
|
||||
printf("\n");
|
||||
|
||||
(void)fflush(stdout);
|
||||
|
||||
rv = xbps_remove_binary_pkg(argv[1], root, flags);
|
||||
if (rv != 0) {
|
||||
if (errno == ENOENT)
|
||||
printf("Package %s is not installed.\n",
|
||||
argv[1]);
|
||||
if (!verbose)
|
||||
printf("failed! (%s)\n", strerror(rv));
|
||||
else
|
||||
printf("Unable to remove %s (%s).\n",
|
||||
argv[1], strerror(errno));
|
||||
printf("Unable to remove %s-%s (%s).\n",
|
||||
argv[1], version, strerror(errno));
|
||||
|
||||
prop_object_release(dict);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("Package %s removed successfully.\n", argv[1]);
|
||||
if (!verbose)
|
||||
printf("done.\n");
|
||||
else
|
||||
printf("Package %s-%s removed successfully.\n",
|
||||
argv[1], version);
|
||||
|
||||
prop_object_release(dict);
|
||||
|
||||
} else if (strcasecmp(argv[0], "show") == 0) {
|
||||
/* Shows info about an installed binary package. */
|
||||
@@ -287,20 +307,76 @@ main(int argc, char **argv)
|
||||
|
||||
} else if (strcasecmp(argv[0], "autoremove") == 0) {
|
||||
/*
|
||||
* Removes orphaned pkgs. These packages were installed
|
||||
* Removes orphan pkgs. These packages were installed
|
||||
* as dependency and any installed package does not depend
|
||||
* on it.
|
||||
* on it currently.
|
||||
*/
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
#if 0
|
||||
rv = xbps_auto_remove_packages();
|
||||
if (rv != 0) {
|
||||
printf("There was an error! (%s)\n", strerror(rv));
|
||||
orphans = xbps_find_orphan_packages();
|
||||
if (orphans == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
if (orphans != NULL && prop_array_count(orphans) == 0) {
|
||||
printf("There are not orphaned packages currently.\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
|
||||
iter = prop_array_iterator(orphans);
|
||||
if (iter == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
printf("The following packages were installed automatically\n"
|
||||
"(as dependencies) and aren't needed anymore:\n");
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname",
|
||||
&pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version",
|
||||
&version);
|
||||
if (count == 0)
|
||||
printf("\n\t");
|
||||
else if (count == 4) {
|
||||
printf("\n\t");
|
||||
count = 0;
|
||||
}
|
||||
printf("%s-%s ", pkgname, version);
|
||||
count++;
|
||||
}
|
||||
printf("\n\n");
|
||||
if (!forcerm) {
|
||||
printf("If you are really sure you don't need them, "
|
||||
"use -f to confirm.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
prop_object_iterator_reset(iter);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname",
|
||||
&pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version",
|
||||
&version);
|
||||
printf("Removing package %s-%s ... ",
|
||||
pkgname, version);
|
||||
if (verbose)
|
||||
printf("\n");
|
||||
|
||||
(void)fflush(stdout);
|
||||
|
||||
rv = xbps_remove_binary_pkg(pkgname, root, flags);
|
||||
if (rv != 0) {
|
||||
if (!verbose)
|
||||
printf("failed! (%s)\n", strerror(rv));
|
||||
prop_object_iterator_release(iter);
|
||||
prop_object_release(orphans);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (!verbose)
|
||||
printf("done.\n");
|
||||
}
|
||||
out:
|
||||
prop_object_iterator_release(iter);
|
||||
prop_object_release(orphans);
|
||||
|
||||
} else {
|
||||
usage();
|
||||
|
||||
Reference in New Issue
Block a user