From 343600261c9fd0ee2ead89ec2e183c3055b510e8 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 22 Dec 2009 14:43:38 +0100 Subject: [PATCH] xbps-bin(8): - Add -y flag to assume "yes" for all questions. - Print a proper error string when the transaction dictionary is empty. --HG-- extra : convert_revision : xtraeme%40gmail.com-20091222134338-u9h0iybexedunm0h --- bin/xbps-bin/install.c | 32 +++++++++++++------------------- bin/xbps-bin/main.c | 30 +++++++++++++++++------------- bin/xbps-bin/xbps-bin.8.txt | 10 ++++++---- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/bin/xbps-bin/install.c b/bin/xbps-bin/install.c index 32b263ee..768148d5 100644 --- a/bin/xbps-bin/install.c +++ b/bin/xbps-bin/install.c @@ -35,7 +35,7 @@ struct transaction { prop_dictionary_t dict; prop_object_iterator_t iter; - bool force; + bool yes; }; static int exec_transaction(struct transaction *); @@ -295,7 +295,7 @@ show_transaction_sizes(prop_object_iterator_t iter) } int -xbps_autoupdate_pkgs(bool force) +xbps_autoupdate_pkgs(bool yes) { int rv = 0; @@ -315,7 +315,7 @@ xbps_autoupdate_pkgs(bool force) return rv; } - return xbps_exec_transaction(force); + return xbps_exec_transaction(yes); } int @@ -330,16 +330,15 @@ xbps_install_new_pkg(const char *pkgname) if ((pkgd = xbps_find_pkg_installed_from_plist(pkgname))) { printf("Package '%s' is already installed.\n", pkgname); prop_object_release(pkgd); - return rv; + return 0; } rv = xbps_repository_install_pkg(pkgname); if (rv != 0 && rv == EAGAIN) { printf("Unable to locate '%s' in " "repository pool.\n", pkgname); - return rv; + rv = 0; } else if (rv != 0 && rv != ENOENT) { printf("Unexpected error: %s", strerror(errno)); - return rv; } return rv; @@ -357,28 +356,23 @@ xbps_update_pkg(const char *pkgname) rv = xbps_repository_update_pkg(pkgname, pkgd); if (rv == EEXIST) { printf("Package '%s' is up to date.\n", pkgname); - prop_object_release(pkgd); - return 0; + rv = 0; } else if (rv == ENOENT) { printf("Package '%s' not found in " "repository pool.\n", pkgname); - prop_object_release(pkgd); - return rv; - } else if (rv != 0) { - prop_object_release(pkgd); - return rv; + rv = 0; } prop_object_release(pkgd); } else { printf("Package '%s' not installed.\n", pkgname); - return rv; + return 0; } return rv; } int -xbps_exec_transaction(bool force) +xbps_exec_transaction(bool yes) { struct transaction *trans; prop_array_t array; @@ -390,7 +384,7 @@ xbps_exec_transaction(bool force) trans->dict = xbps_repository_get_transaction_dict(); if (trans->dict == NULL) { - printf("error: unexistent props dictionary!\n"); + printf("Empty transaction, exiting.\n"); goto out1; } @@ -423,7 +417,7 @@ xbps_exec_transaction(bool force) goto out2; } - trans->force = force; + trans->yes = yes; rv = exec_transaction(trans); prop_object_iterator_release(trans->iter); @@ -499,9 +493,9 @@ exec_transaction(struct transaction *trans) return rv; /* - * Ask interactively (if -f not set). + * Ask interactively (if -y not set). */ - if (trans->force == false) { + if (trans->yes == false) { if (xbps_noyes("Do you want to continue?") == false) { printf("Aborting!\n"); return 0; diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index ccaa4b70..59ae2af9 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -46,24 +46,26 @@ usage(void) " autoremove\n" " autoupdate\n" " check\t\t[|]\n" - " install\t\t\n" + " install\t\t\n" " list\n" " list-manual\n" " purge\t\t[|]\n" " reconfigure\t\t[|]\n" - " remove\t\t\n" + " remove\t\t\n" " show\t\t\n" " show-deps\t\t\n" " show-files\t\t\n" " show-revdeps\t\n" - " update\t\t\n" + " update\t\t\n" " Options shared by all targets:\n" " -c\t\t\n" " -r\t\t\n" " -v\t\tShows verbose messages\n" " -V\t\tPrints the xbps release version\n" " Options used by the install/(auto)remove/update targets:\n" - " -f\t\tBypasses the questions.\n" + " -y\t\tAssume \"yes\" for all questions.\n" + " Options used by the reconfigure target:\n" + " -f\t\tForce reconfiguration.\n" "\n"); exit(EXIT_FAILURE); } @@ -112,18 +114,17 @@ main(int argc, char **argv) prop_dictionary_t dict; struct sigaction sa; int i = 0, c, flags = 0, rv = 0; - bool force, verbose; + bool yes, verbose; - force = verbose = false; + yes = verbose = false; - while ((c = getopt(argc, argv, "Vcfr:v")) != -1) { + while ((c = getopt(argc, argv, "Vcfr:vy")) != -1) { switch (c) { case 'c': xbps_set_cachedir(optarg); break; case 'f': flags |= XBPS_FLAG_FORCE; - force = true; break; case 'r': /* To specify the root directory */ @@ -136,6 +137,9 @@ main(int argc, char **argv) case 'V': printf("%s\n", XBPS_RELVER); exit(EXIT_SUCCESS); + case 'y': + yes = true; + break; case '?': default: usage(); @@ -194,7 +198,7 @@ main(int argc, char **argv) if ((rv = xbps_install_new_pkg(argv[i])) != 0) goto out; - rv = xbps_exec_transaction(force); + rv = xbps_exec_transaction(yes); } else if (strcasecmp(argv[0], "update") == 0) { /* Update an installed package. */ @@ -205,14 +209,14 @@ main(int argc, char **argv) if ((rv = xbps_update_pkg(argv[i])) != 0) goto out; - rv = xbps_exec_transaction(force); + rv = xbps_exec_transaction(yes); } else if (strcasecmp(argv[0], "remove") == 0) { /* Removes a binary package. */ if (argc < 2) usage(); - rv = xbps_remove_installed_pkgs(argc, argv, force); + rv = xbps_remove_installed_pkgs(argc, argv, yes); } else if (strcasecmp(argv[0], "show") == 0) { /* Shows info about an installed binary package. */ @@ -253,7 +257,7 @@ main(int argc, char **argv) if (argc != 1) usage(); - rv = xbps_autoupdate_pkgs(force); + rv = xbps_autoupdate_pkgs(yes); } else if (strcasecmp(argv[0], "autoremove") == 0) { /* @@ -264,7 +268,7 @@ main(int argc, char **argv) if (argc != 1) usage(); - rv = xbps_autoremove_pkgs(force); + rv = xbps_autoremove_pkgs(yes); } else if (strcasecmp(argv[0], "purge") == 0) { /* diff --git a/bin/xbps-bin/xbps-bin.8.txt b/bin/xbps-bin/xbps-bin.8.txt index cfe70e1c..6679f9b1 100644 --- a/bin/xbps-bin/xbps-bin.8.txt +++ b/bin/xbps-bin/xbps-bin.8.txt @@ -31,10 +31,8 @@ OPTIONS it will become '/blah/cachedir'. *-f*:: - By default while installing or removing packages, xbps-bin(1) - will ask you if you are sure about the task that will be done. - This option bypasses the question and executes the task immediately. - Use this option carefully. + Used currently in the 'reconfigure' target. If set, package(s) will + be reconfigured regardless of its state. *-r* 'rootdir':: Sets the 'root' directory. By default the root directory is @@ -46,6 +44,10 @@ OPTIONS *-v*:: Shows verbose messages. Useful while installing and removing packages. +*-y*:: + Assume "yes" to all questions. This will bypass all questions and + immediately proceed with the task, use this option with care. + *-V*:: Shows the current XBPS release version (library and code).