diff --git a/NEWS b/NEWS index 8a836d97..c7ff461d 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ 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 been already added previously. diff --git a/bin/xbps-bin/defs.h b/bin/xbps-bin/defs.h index bbc4f896..abc5d75f 100644 --- a/bin/xbps-bin/defs.h +++ b/bin/xbps-bin/defs.h @@ -29,9 +29,9 @@ int xbps_install_new_pkg(const char *); int xbps_update_pkg(const char *); int xbps_autoupdate_pkgs(bool); -int xbps_autoremove_pkgs(bool); +int xbps_autoremove_pkgs(bool, 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_all(void); int xbps_show_pkg_deps(const char *); diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index e9ea75b0..d621fba0 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -61,6 +61,7 @@ usage(void) " -V\t\tPrints the xbps release version\n" " Options used by the install/(auto)remove/update targets:\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" " -f\t\tForce reconfiguration or removal of files.\n" "\n"); @@ -119,11 +120,11 @@ main(int argc, char **argv) prop_dictionary_t dict; struct sigaction sa; 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) { case 'c': xbps_set_cachedir(optarg); @@ -131,6 +132,9 @@ main(int argc, char **argv) case 'f': flags |= XBPS_FLAG_FORCE; break; + case 'p': + purge = true; + break; case 'r': /* To specify the root directory */ xbps_set_rootdir(optarg); @@ -222,7 +226,7 @@ main(int argc, char **argv) if (argc < 2) 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) { /* Shows info about an installed binary package. */ @@ -274,7 +278,7 @@ main(int argc, char **argv) if (argc != 1) usage(); - rv = xbps_autoremove_pkgs(yes); + rv = xbps_autoremove_pkgs(yes, purge); } else if (strcasecmp(argv[0], "purge") == 0) { /* diff --git a/bin/xbps-bin/remove.c b/bin/xbps-bin/remove.c index d8e5a6d4..f0965507 100644 --- a/bin/xbps-bin/remove.c +++ b/bin/xbps-bin/remove.c @@ -33,8 +33,36 @@ #include "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 -xbps_autoremove_pkgs(bool force) +xbps_autoremove_pkgs(bool force, bool purge) { prop_array_t orphans = NULL; prop_object_t obj = NULL; @@ -103,8 +131,7 @@ xbps_autoremove_pkgs(bool force) rv = errno; goto out; } - printf("Removing package %s-%s ...\n", pkgname, version); - if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0) + if ((rv = pkg_remove_and_purge(pkgname, version, purge)) != 0) goto out; } @@ -118,7 +145,7 @@ out: } 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_dictionary_t dict; @@ -185,12 +212,8 @@ xbps_remove_installed_pkgs(int argc, char **argv, bool force) if (dict == NULL) continue; prop_dictionary_get_cstring_nocopy(dict, "version", &version); - printf("Removing package %s-%s ...\n", argv[i], version); - 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)); + if ((rv = pkg_remove_and_purge(argv[i], version, purge)) != 0) return rv; - } } return 0; diff --git a/bin/xbps-bin/xbps-bin.8.txt b/bin/xbps-bin/xbps-bin.8.txt index 4ab2b239..cafd78ab 100644 --- a/bin/xbps-bin/xbps-bin.8.txt +++ b/bin/xbps-bin/xbps-bin.8.txt @@ -36,6 +36,11 @@ OPTIONS with the 'reconfigure target, or to force removal of package files 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':: Sets the 'root' directory. By default the root directory is set to '/'. Please note that the database directory is always