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
This commit is contained in:
Juan RP 2009-12-22 14:43:38 +01:00
parent 7eea0f8e8e
commit 343600261c
3 changed files with 36 additions and 36 deletions

View File

@ -35,7 +35,7 @@
struct transaction { struct transaction {
prop_dictionary_t dict; prop_dictionary_t dict;
prop_object_iterator_t iter; prop_object_iterator_t iter;
bool force; bool yes;
}; };
static int exec_transaction(struct transaction *); static int exec_transaction(struct transaction *);
@ -295,7 +295,7 @@ show_transaction_sizes(prop_object_iterator_t iter)
} }
int int
xbps_autoupdate_pkgs(bool force) xbps_autoupdate_pkgs(bool yes)
{ {
int rv = 0; int rv = 0;
@ -315,7 +315,7 @@ xbps_autoupdate_pkgs(bool force)
return rv; return rv;
} }
return xbps_exec_transaction(force); return xbps_exec_transaction(yes);
} }
int int
@ -330,16 +330,15 @@ xbps_install_new_pkg(const char *pkgname)
if ((pkgd = xbps_find_pkg_installed_from_plist(pkgname))) { if ((pkgd = xbps_find_pkg_installed_from_plist(pkgname))) {
printf("Package '%s' is already installed.\n", pkgname); printf("Package '%s' is already installed.\n", pkgname);
prop_object_release(pkgd); prop_object_release(pkgd);
return rv; return 0;
} }
rv = xbps_repository_install_pkg(pkgname); rv = xbps_repository_install_pkg(pkgname);
if (rv != 0 && rv == EAGAIN) { if (rv != 0 && rv == EAGAIN) {
printf("Unable to locate '%s' in " printf("Unable to locate '%s' in "
"repository pool.\n", pkgname); "repository pool.\n", pkgname);
return rv; rv = 0;
} else if (rv != 0 && rv != ENOENT) { } else if (rv != 0 && rv != ENOENT) {
printf("Unexpected error: %s", strerror(errno)); printf("Unexpected error: %s", strerror(errno));
return rv;
} }
return rv; return rv;
@ -357,28 +356,23 @@ xbps_update_pkg(const char *pkgname)
rv = xbps_repository_update_pkg(pkgname, pkgd); rv = xbps_repository_update_pkg(pkgname, pkgd);
if (rv == EEXIST) { if (rv == EEXIST) {
printf("Package '%s' is up to date.\n", pkgname); printf("Package '%s' is up to date.\n", pkgname);
prop_object_release(pkgd); rv = 0;
return 0;
} else if (rv == ENOENT) { } else if (rv == ENOENT) {
printf("Package '%s' not found in " printf("Package '%s' not found in "
"repository pool.\n", pkgname); "repository pool.\n", pkgname);
prop_object_release(pkgd); rv = 0;
return rv;
} else if (rv != 0) {
prop_object_release(pkgd);
return rv;
} }
prop_object_release(pkgd); prop_object_release(pkgd);
} else { } else {
printf("Package '%s' not installed.\n", pkgname); printf("Package '%s' not installed.\n", pkgname);
return rv; return 0;
} }
return rv; return rv;
} }
int int
xbps_exec_transaction(bool force) xbps_exec_transaction(bool yes)
{ {
struct transaction *trans; struct transaction *trans;
prop_array_t array; prop_array_t array;
@ -390,7 +384,7 @@ xbps_exec_transaction(bool force)
trans->dict = xbps_repository_get_transaction_dict(); trans->dict = xbps_repository_get_transaction_dict();
if (trans->dict == NULL) { if (trans->dict == NULL) {
printf("error: unexistent props dictionary!\n"); printf("Empty transaction, exiting.\n");
goto out1; goto out1;
} }
@ -423,7 +417,7 @@ xbps_exec_transaction(bool force)
goto out2; goto out2;
} }
trans->force = force; trans->yes = yes;
rv = exec_transaction(trans); rv = exec_transaction(trans);
prop_object_iterator_release(trans->iter); prop_object_iterator_release(trans->iter);
@ -499,9 +493,9 @@ exec_transaction(struct transaction *trans)
return rv; 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) { if (xbps_noyes("Do you want to continue?") == false) {
printf("Aborting!\n"); printf("Aborting!\n");
return 0; return 0;

View File

@ -46,24 +46,26 @@ usage(void)
" autoremove\n" " autoremove\n"
" autoupdate\n" " autoupdate\n"
" check\t\t[<pkgname>|<all>]\n" " check\t\t[<pkgname>|<all>]\n"
" install\t\t<pkgname>\n" " install\t\t<pkgname(s)>\n"
" list\n" " list\n"
" list-manual\n" " list-manual\n"
" purge\t\t[<pkgname>|<all>]\n" " purge\t\t[<pkgname>|<all>]\n"
" reconfigure\t\t[<pkgname>|<all>]\n" " reconfigure\t\t[<pkgname>|<all>]\n"
" remove\t\t<pkgname>\n" " remove\t\t<pkgname(s)>\n"
" show\t\t<pkgname>\n" " show\t\t<pkgname>\n"
" show-deps\t\t<pkgname>\n" " show-deps\t\t<pkgname>\n"
" show-files\t\t<pkgname>\n" " show-files\t\t<pkgname>\n"
" show-revdeps\t<pkgname>\n" " show-revdeps\t<pkgname>\n"
" update\t\t<pkgname>\n" " update\t\t<pkgname(s)>\n"
" Options shared by all targets:\n" " Options shared by all targets:\n"
" -c\t\t<cachedir>\n" " -c\t\t<cachedir>\n"
" -r\t\t<rootdir>\n" " -r\t\t<rootdir>\n"
" -v\t\tShows verbose messages\n" " -v\t\tShows verbose messages\n"
" -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"
" -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"); "\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -112,18 +114,17 @@ 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 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) { switch (c) {
case 'c': case 'c':
xbps_set_cachedir(optarg); xbps_set_cachedir(optarg);
break; break;
case 'f': case 'f':
flags |= XBPS_FLAG_FORCE; flags |= XBPS_FLAG_FORCE;
force = true;
break; break;
case 'r': case 'r':
/* To specify the root directory */ /* To specify the root directory */
@ -136,6 +137,9 @@ main(int argc, char **argv)
case 'V': case 'V':
printf("%s\n", XBPS_RELVER); printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'y':
yes = true;
break;
case '?': case '?':
default: default:
usage(); usage();
@ -194,7 +198,7 @@ main(int argc, char **argv)
if ((rv = xbps_install_new_pkg(argv[i])) != 0) if ((rv = xbps_install_new_pkg(argv[i])) != 0)
goto out; goto out;
rv = xbps_exec_transaction(force); rv = xbps_exec_transaction(yes);
} else if (strcasecmp(argv[0], "update") == 0) { } else if (strcasecmp(argv[0], "update") == 0) {
/* Update an installed package. */ /* Update an installed package. */
@ -205,14 +209,14 @@ main(int argc, char **argv)
if ((rv = xbps_update_pkg(argv[i])) != 0) if ((rv = xbps_update_pkg(argv[i])) != 0)
goto out; goto out;
rv = xbps_exec_transaction(force); rv = xbps_exec_transaction(yes);
} else if (strcasecmp(argv[0], "remove") == 0) { } else if (strcasecmp(argv[0], "remove") == 0) {
/* Removes a binary package. */ /* Removes a binary package. */
if (argc < 2) if (argc < 2)
usage(); usage();
rv = xbps_remove_installed_pkgs(argc, argv, force); rv = xbps_remove_installed_pkgs(argc, argv, yes);
} 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. */
@ -253,7 +257,7 @@ main(int argc, char **argv)
if (argc != 1) if (argc != 1)
usage(); usage();
rv = xbps_autoupdate_pkgs(force); rv = xbps_autoupdate_pkgs(yes);
} else if (strcasecmp(argv[0], "autoremove") == 0) { } else if (strcasecmp(argv[0], "autoremove") == 0) {
/* /*
@ -264,7 +268,7 @@ main(int argc, char **argv)
if (argc != 1) if (argc != 1)
usage(); usage();
rv = xbps_autoremove_pkgs(force); rv = xbps_autoremove_pkgs(yes);
} else if (strcasecmp(argv[0], "purge") == 0) { } else if (strcasecmp(argv[0], "purge") == 0) {
/* /*

View File

@ -31,10 +31,8 @@ OPTIONS
it will become '/blah/cachedir'. it will become '/blah/cachedir'.
*-f*:: *-f*::
By default while installing or removing packages, xbps-bin(1) Used currently in the 'reconfigure' target. If set, package(s) will
will ask you if you are sure about the task that will be done. be reconfigured regardless of its state.
This option bypasses the question and executes the task immediately.
Use this option carefully.
*-r* 'rootdir':: *-r* 'rootdir'::
Sets the 'root' directory. By default the root directory is Sets the 'root' directory. By default the root directory is
@ -46,6 +44,10 @@ OPTIONS
*-v*:: *-v*::
Shows verbose messages. Useful while installing and removing packages. 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*:: *-V*::
Shows the current XBPS release version (library and code). Shows the current XBPS release version (library and code).