xbps-bin(8): added -p flag to also purge packages for the 'remove'

and 'autoremove' targets, after successful removal.

--HG--
extra : convert_revision : xtraeme%40gmail.com-20100428012613-e2wpzknmrxkjntsd
This commit is contained in:
Juan RP 2010-04-28 03:26:13 +02:00
parent 1771aacfab
commit e274585c3c
5 changed files with 51 additions and 16 deletions

3
NEWS
View File

@ -1,5 +1,8 @@
xbps-0.5.0 (2010-05-01): xbps-0.5.0 (2010-05-01):
* xbps-bin(8): added new flag '-p' for the 'remove' and 'autoremove'
targets, to also purge the package(s) after successful removal.
* xbps-repo(8): print a warning when registering a repository that has * xbps-repo(8): print a warning when registering a repository that has
been already added previously. been already added previously.

View File

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

View File

@ -61,6 +61,7 @@ usage(void)
" -V\t\tPrints the xbps release version\n" " -V\t\tPrints the xbps release version\n"
" Options used by the install/(auto)remove/update targets:\n" " Options used by the install/(auto)remove/update targets:\n"
" -y\t\tAssume \"yes\" for all questions.\n" " -y\t\tAssume \"yes\" for all questions.\n"
" -p\t\tAlso purge package(s) in the (auto)remove targets.\n"
" Options used by the purge/reconfigure/remove targets:\n" " Options used by the purge/reconfigure/remove targets:\n"
" -f\t\tForce reconfiguration or removal of files.\n" " -f\t\tForce reconfiguration or removal of files.\n"
"\n"); "\n");
@ -119,11 +120,11 @@ main(int argc, char **argv)
prop_dictionary_t dict; prop_dictionary_t dict;
struct sigaction sa; struct sigaction sa;
int i = 0, c, flags = 0, rv = 0; int i = 0, c, flags = 0, rv = 0;
bool yes, verbose; bool yes, verbose, purge;
yes = verbose = false; yes = verbose = purge = false;
while ((c = getopt(argc, argv, "Vcfr:vy")) != -1) { while ((c = getopt(argc, argv, "Vcfpr:vy")) != -1) {
switch (c) { switch (c) {
case 'c': case 'c':
xbps_set_cachedir(optarg); xbps_set_cachedir(optarg);
@ -131,6 +132,9 @@ main(int argc, char **argv)
case 'f': case 'f':
flags |= XBPS_FLAG_FORCE; flags |= XBPS_FLAG_FORCE;
break; break;
case 'p':
purge = true;
break;
case 'r': case 'r':
/* To specify the root directory */ /* To specify the root directory */
xbps_set_rootdir(optarg); xbps_set_rootdir(optarg);
@ -222,7 +226,7 @@ main(int argc, char **argv)
if (argc < 2) if (argc < 2)
usage(); usage();
rv = xbps_remove_installed_pkgs(argc, argv, yes); rv = xbps_remove_installed_pkgs(argc, argv, yes, purge);
} else if (strcasecmp(argv[0], "show") == 0) { } else if (strcasecmp(argv[0], "show") == 0) {
/* Shows info about an installed binary package. */ /* Shows info about an installed binary package. */
@ -274,7 +278,7 @@ main(int argc, char **argv)
if (argc != 1) if (argc != 1)
usage(); usage();
rv = xbps_autoremove_pkgs(yes); rv = xbps_autoremove_pkgs(yes, purge);
} else if (strcasecmp(argv[0], "purge") == 0) { } else if (strcasecmp(argv[0], "purge") == 0) {
/* /*

View File

@ -33,8 +33,36 @@
#include "defs.h" #include "defs.h"
#include "../xbps-repo/defs.h" #include "../xbps-repo/defs.h"
static int
pkg_remove_and_purge(const char *pkgname, const char *version, bool purge)
{
int rv = 0;
printf("Removing package %s-%s ... ", pkgname, version);
(void)fflush(stdout);
if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0) {
fprintf(stderr, "\nE: unable to remove %s-%s (%s).\n",
pkgname, version, strerror(errno));
return rv;
}
if (purge) {
printf("purging ... ");
(void)fflush(stdout);
if ((rv = xbps_purge_pkg(pkgname, false)) != 0) {
fprintf(stderr, "\nE: unable to purge %s-%s "
"(%s).\n", pkgname, version,
strerror(errno));
return rv;
}
}
printf("done.\n");
return rv;
}
int int
xbps_autoremove_pkgs(bool force) xbps_autoremove_pkgs(bool force, bool purge)
{ {
prop_array_t orphans = NULL; prop_array_t orphans = NULL;
prop_object_t obj = NULL; prop_object_t obj = NULL;
@ -103,8 +131,7 @@ xbps_autoremove_pkgs(bool force)
rv = errno; rv = errno;
goto out; goto out;
} }
printf("Removing package %s-%s ...\n", pkgname, version); if ((rv = pkg_remove_and_purge(pkgname, version, purge)) != 0)
if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0)
goto out; goto out;
} }
@ -118,7 +145,7 @@ out:
} }
int int
xbps_remove_installed_pkgs(int argc, char **argv, bool force) xbps_remove_installed_pkgs(int argc, char **argv, bool force, bool purge)
{ {
prop_array_t reqby; prop_array_t reqby;
prop_dictionary_t dict; prop_dictionary_t dict;
@ -185,12 +212,8 @@ xbps_remove_installed_pkgs(int argc, char **argv, bool force)
if (dict == NULL) if (dict == NULL)
continue; continue;
prop_dictionary_get_cstring_nocopy(dict, "version", &version); prop_dictionary_get_cstring_nocopy(dict, "version", &version);
printf("Removing package %s-%s ...\n", argv[i], version); if ((rv = pkg_remove_and_purge(argv[i], version, purge)) != 0)
if ((rv = xbps_remove_pkg(argv[i], version, false)) != 0) {
fprintf(stderr, "E: unable to remove %s-%s (%s).\n",
argv[i], version, strerror(errno));
return rv; return rv;
}
} }
return 0; return 0;

View File

@ -36,6 +36,11 @@ OPTIONS
with the 'reconfigure target, or to force removal of package files with the 'reconfigure target, or to force removal of package files
even if its hash doesn't match in the 'purge' and 'remove' targets. even if its hash doesn't match in the 'purge' and 'remove' targets.
*-p*::
Used currently in the 'remove' and 'autoremove' targets, if enabled
after removing a package it is also purged.
*-r* 'rootdir':: *-r* 'rootdir'::
Sets the 'root' directory. By default the root directory is Sets the 'root' directory. By default the root directory is
set to '/'. Please note that the database directory is always set to '/'. Please note that the database directory is always