xbps-bin(8): added -R option to recursively remove pkgs that were instaled automatically.

This commit is contained in:
Juan RP
2011-01-30 08:08:34 +01:00
parent bb897da7b4
commit 7da33469cc
7 changed files with 141 additions and 40 deletions

View File

@@ -37,7 +37,7 @@ int xbps_update_pkg(const char *);
int xbps_autoupdate_pkgs(bool, bool);
int xbps_autoremove_pkgs(bool, bool);
int xbps_exec_transaction(bool, bool);
int xbps_remove_installed_pkgs(int, char **, bool, bool, bool);
int xbps_remove_installed_pkgs(int, char **, bool, bool, bool, bool);
int xbps_check_pkg_integrity(const char *);
int xbps_check_pkg_integrity_all(void);
int xbps_show_pkg_deps(const char *);

View File

@@ -121,7 +121,7 @@ show_orphans(void)
prop_object_t obj;
const char *pkgver;
orphans = xbps_find_pkg_orphans();
orphans = xbps_find_pkg_orphans(NULL);
if (orphans == NULL)
return EINVAL;
@@ -155,13 +155,13 @@ main(int argc, char **argv)
struct list_pkgver_cb lpc;
struct sigaction sa;
int i , c, flags, rv;
bool yes, purge, with_debug, force_rm_with_deps;
bool yes, purge, with_debug, force_rm_with_deps, recursive_rm;
bool show_download_pkglist_url = false;
i = c = flags = rv = 0;
yes = purge = force_rm_with_deps = with_debug = false;
yes = purge = force_rm_with_deps = recursive_rm = with_debug = false;
while ((c = getopt(argc, argv, "VcdDFfpr:vy")) != -1) {
while ((c = getopt(argc, argv, "VcdDFfpRr:vy")) != -1) {
switch (c) {
case 'c':
xbps_set_cachedir(optarg);
@@ -181,6 +181,9 @@ main(int argc, char **argv)
case 'p':
purge = true;
break;
case 'R':
recursive_rm = true;
break;
case 'r':
/* To specify the root directory */
xbps_set_rootdir(optarg);
@@ -304,7 +307,7 @@ main(int argc, char **argv)
usage();
rv = xbps_remove_installed_pkgs(argc, argv, yes, purge,
force_rm_with_deps);
force_rm_with_deps, recursive_rm);
} else if (strcasecmp(argv[0], "show") == 0) {
/* Shows info about an installed binary package. */

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2010 Juan Romero Pardines.
* Copyright (c) 2008-2011 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -74,7 +74,7 @@ xbps_autoremove_pkgs(bool yes, bool purge)
* as dependency and any installed package does not depend
* on it currently.
*/
orphans = xbps_find_pkg_orphans();
orphans = xbps_find_pkg_orphans(NULL);
if (orphans == NULL)
return errno;
@@ -120,11 +120,14 @@ out:
}
int
xbps_remove_installed_pkgs(int argc, char **argv, bool yes, bool purge,
bool force_rm_with_deps)
xbps_remove_installed_pkgs(int argc,
char **argv,
bool yes,
bool purge,
bool force_rm_with_deps,
bool recursive_rm)
{
prop_array_t sorted_pkgs;
prop_array_t reqby;
prop_array_t sorted_pkgs, orphans, reqby, orphans_user = NULL;
prop_dictionary_t dict;
size_t x;
const char *version, *pkgver, *pkgname;
@@ -135,6 +138,32 @@ xbps_remove_installed_pkgs(int argc, char **argv, bool yes, bool purge,
if (sorted_pkgs == NULL)
return -1;
/*
* If recursively removing packages, find out which packages
* would be orphans if the supplied package names were removed.
*/
if (recursive_rm) {
orphans_user = prop_array_create();
if (orphans_user == NULL) {
xbps_error_printf("NULL orphans_user array\n");
return ENOMEM;
}
for (x = 0, i = 1; i < argc; i++, x++)
prop_array_set_cstring_nocopy(orphans_user, x, argv[i]);
orphans = xbps_find_pkg_orphans(orphans_user);
prop_object_release(orphans_user);
if (orphans == NULL) {
xbps_error_printf("NULL orphans array\n");
return EINVAL;
}
/* in reverse order */
x = prop_array_count(orphans);
while (x--)
prop_array_add(sorted_pkgs, prop_array_get(orphans, x));
prop_object_release(orphans);
}
/*
* First check if package is required by other packages.
*/
@@ -144,13 +173,18 @@ xbps_remove_installed_pkgs(int argc, char **argv, bool yes, bool purge,
printf("Package %s is not installed.\n", argv[i]);
continue;
}
/*
* Check that current package is not required by
* other installed packages.
*/
prop_array_add(sorted_pkgs, dict);
prop_dictionary_get_cstring_nocopy(dict, "pkgver", &pkgver);
found = true;
reqby = prop_dictionary_get(dict, "requiredby");
if (reqby != NULL && prop_array_count(reqby) > 0) {
xbps_warn_printf("%s IS REQUIRED BY %u PACKAGES!\n",
pkgver, prop_array_count(reqby));
xbps_printf("WARNING: %s IS REQUIRED BY %u "
"PACKAGE%s!\n", pkgver, prop_array_count(reqby),
prop_array_count(reqby) > 1 ? "S" : "");
reqby_force = true;
}
prop_object_release(dict);
@@ -159,8 +193,6 @@ xbps_remove_installed_pkgs(int argc, char **argv, bool yes, bool purge,
prop_object_release(sorted_pkgs);
return 0;
}
/*
* Show the list of going-to-be removed packages.
*/

View File

@@ -1,4 +1,4 @@
.TH "XBPS\-BIN" "8" "27/01/2011" "\ \&" "\ \&"
.TH "XBPS\-BIN" "8" "30/01/2011" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
@@ -77,6 +77,14 @@ and
targets, if enabled after removing a package it is also purged\&.
.RE
.PP
\fB\-R\fR
.RS 4
Used currently in the
\fIremove\fR
target, to recursively remove packages that aren\(cqt required by other installed
packages and that were installed by the package that we want to remove\&.
.RE
.PP
\fB\-r\fR \fIrootdir\fR
.RS 4
Sets the
@@ -222,7 +230,7 @@ state, it must be
\fBpurged\fR
with the
\fBpurge\fR
command\&. If
command or alternatively use the \fI\-p\fR flag \&. If
\fB\-f\fR
option is used, package files will be removed even if its SHA256 hash doesn\(cqt match\&.
.RE
@@ -329,35 +337,41 @@ directory for downloaded binary packages\&.
.RE
.SH "EXAMPLES"
.PP
\fBInstall a package by specifying its name:\fR
Install a package by specifying its name:
.RS 4
$ xbps\-bin install foo
.RE
.PP
\fBInstall a package by specifying a package pattern:\fR
Install a package by specifying a package pattern:
.RS 4
$ xbps\-bin install "\fBfoo>=3\&.0\fR"
.RE
.PP
\fBInstall multiple packages by specifying names and package patterns:\fR
Install multiple packages by specifying names and package patterns:
.RS 4
$ xbps\-bin install foo "\fBblah⇐4\&.0\fR" baz\-2\&.0 "\fBblob>4\&.[0\-9]\fR"
.RE
.PP
\fBFind the package that owns the file \fB/bin/mount\fR:\fR
Find the package that owns the file \fB/bin/mount\fR:
.RS 4
$ xbps\-bin find\-files /bin/mount
.RE
.PP
\fBFind the packages that match the pattern "\fB/usr/lib/libav\&*\fR":
Find the packages that match the pattern "\fB/usr/lib/libav\&*\fR":
.RS 4
$ xbps\-bin find\-files "/usr/lib/libav\&*"
.RE
.PP
\fBRemove and purge the package \fBproplib-devel\fR:\fR
Remove and purge the package \fBproplib-devel\fR:
.RS 4
$ xbps\-bin -yp remove proplib\-devel
.RE
.PP
Remove and purge the package \fBbsdtar\fR and recursively all packages that
were installed automatically by it:
.RS 4
$ xbps\-bin -Rp remove bsdtar
.RE
.SH "BUGS"
.sp
Probably, but I try to make this not happen\&. Use it under your own responsability and enjoy your life\&.