Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkg.conf(5) option DEFAULT_ALWAYS_YES. When this option is enabled pkg(1) will default to "yes" for all questions which require user confirmation before doing anything.
Erik Nordstroem committed 11 years ago
commit eabd4fb09077dbf6bb511193c02c4617987115a0
parent 0b0b1b0
25 files changed +77 -27
modified docs/pkg-add.8
@@ -106,6 +106,7 @@ See
.Xr pkg.conf 5
for further description.
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
+
.It Ev DEFAULT_ALWAYS_YES
.It Ev ASSUME_ALWAYS_YES
.It Ev HANDLE_RC_SCRIPTS
.It Ev PKG_DBDIR
modified docs/pkg-annotate.8
@@ -160,6 +160,7 @@ See
for further description.
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
.It Ev PKG_DBDIR
+
.It Ev DEFAULT_ALWAYS_YES
.It Ev ASSUME_ALWAYS_YES
.It Ev CASE_SENSITIVE_MATCH
.El
modified docs/pkg-autoremove.8
@@ -51,6 +51,7 @@ See
.Xr pkg.conf 5
for further description.
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
+
.It Ev DEFAULT_ALWAYS_YES
.It Ev ASSUME_ALWAYS_YES
.It Ev HANDLE_RC_SCRIPTS
.It Ev PKG_DBDIR
modified docs/pkg-clean.8
@@ -64,6 +64,7 @@ See
.Xr pkg.conf 5
for further description.
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
+
.It Ev DEFAULT_ALWAYS_YES
.It Ev ASSUME_ALWAYS_YES
.It Ev PKG_DBDIR
.It Ev PKG_CONFIG_CACHEDIR
modified docs/pkg-delete.8
@@ -112,6 +112,7 @@ See
.Xr pkg.conf 5
for further description.
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
+
.It Ev DEFAULT_ALWAYS_YES
.It Ev ASSUME_ALWAYS_YES
.It Ev HANDLE_RC_SCRIPTS
.It Ev PKG_DBDIR
modified docs/pkg-install.8
@@ -189,6 +189,7 @@ See
.Xr pkg.conf 5
for further description.
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
+
.It Ev DEFAULT_ALWAYS_YES
.It Ev ASSUME_ALWAYS_YES
.It Ev CASE_SENSITIVE_MATCH
.It Ev HANDLE_RC_SCRIPTS
modified docs/pkg-lock.8
@@ -133,6 +133,7 @@ See
for further description.
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
.It Ev PKG_DBDIR
+
.It Ev DEFAULT_ALWAYS_YES
.It Ev ASSUME_ALWAYS_YES
.It Ev CASE_SENSITIVE_MATCH
.El
modified docs/pkg-upgrade.8
@@ -182,6 +182,7 @@ See
.Xr pkg.conf 5
for further description.
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
+
.It Ev DEFAULT_ALWAYS_YES
.It Ev ASSUME_ALWAYS_YES
.It Ev HANDLE_RC_SCRIPTS
.It Ev PKG_CACHEDIR
modified docs/pkg.conf.5
@@ -72,6 +72,12 @@ a syntactically correct
command line when substituted in and followed by any remaining tokens from
the original command line.
Default: not set.
+
.It Cm DEFAULT_ALWAYS_YES: boolean
+
When this option is enabled
+
.Xr pkg 1
+
will default to "yes" for all questions
+
which require user confirmation before doing anything.
+
Default: NO.
.It Cm ASSUME_ALWAYS_YES: boolean
When this option is enabled
.Xr pkg 1
modified libpkg/pkg_config.c
@@ -116,6 +116,12 @@ static struct config_entry c[] = {
	},
	{
		PKG_BOOL,
+
		"DEFAULT_ALWAYS_YES",
+
		"NO",
+
		"Default to 'yes' for all pkg(8) questions",
+
	},
+
	{
+
		PKG_BOOL,
		"ASSUME_ALWAYS_YES",
		"NO",
		"Answer 'yes' to all pkg(8) questions",
modified src/annotate.c
@@ -72,7 +72,7 @@ do_add(struct pkgdb *db, struct pkg *pkg, const char *tag, const char *value)


	if (yes || query_tty_yesno(false, "%n-%v: Add annotation tagged: %S with "
-
	               "value: %S? [y/N]: ", pkg, pkg, tag, value)) {
+
	               "value: %S? ", pkg, pkg, tag, value)) {

		ret = pkgdb_add_annotation(db, pkg, tag, value);
		if (ret == EPKG_OK) {
@@ -99,7 +99,7 @@ do_modify(struct pkgdb *db, struct pkg *pkg, const char *tag, const char *value)


	if (yes || query_tty_yesno(false, "%n-%v: Change annotation tagged: %S to "
-
		         "new value: %S? [y/N]: ", pkg, pkg, tag, value)) {
+
		         "new value: %S? ", pkg, pkg, tag, value)) {
		ret = pkgdb_modify_annotation(db, pkg, tag, value);
		if (ret == EPKG_OK || ret == EPKG_WARN) {
			if (!quiet)
@@ -118,8 +118,8 @@ do_delete(struct pkgdb *db, struct pkg *pkg, const char *tag)
{
	int	ret = EPKG_OK;

-
	if (yes || query_tty_yesno(false, "%n-%v: Delete annotation tagged: %S? "
-
			 "[y/N]: ", pkg, pkg, tag)) {
+
	if (yes || query_tty_yesno(false, "%n-%v: Delete annotation tagged: %S? ",
+
			 pkg, pkg, tag)) {
		ret = pkgdb_delete_annotation(db, pkg, tag);
		if (ret == EPKG_OK) {
			if (!quiet)
modified src/autoremove.c
@@ -136,7 +136,7 @@ exec_autoremove(int argc, char **argv)
				"Deinstallation has been requested for the following %d packages:\n\n", nbactions);
		if (!dry_run)
			rc = query_yesno(false,
-
		            "\nProceed with deinstalling packages? [y/N]: ");
+
		            "\nProceed with deinstalling packages? ");
	}
	if (!rc || dry_run || (retcode = pkg_jobs_apply(jobs)) != EPKG_OK) {
		goto cleanup;
modified src/check.c
@@ -172,7 +172,7 @@ fix_deps(struct pkgdb *db, struct deps_head *dh, int nbpkgs, bool yes)
	/* print a summary before applying the jobs */
	print_jobs_summary(jobs, "The following packages will be installed:\n\n");
	
-
	rc = query_yesno(false, "\n>>> Try to fix the missing dependencies? [y/N]: ");
+
	rc = query_yesno(false, "\n>>> Try to fix the missing dependencies? ");

	if (rc) {
		if (pkgdb_access(PKGDB_MODE_WRITE, PKGDB_DB_LOCAL) ==
modified src/clean.c
@@ -330,7 +330,7 @@ exec_clean(int argc, char **argv)
	printf("The cleanup will free %s\n", size);
	if (!dry_run) {
			if (query_yesno(false,
-
			  "\nProceed with cleaning the cache? [y/N]: ")) {
+
			  "\nProceed with cleaning the cache? ")) {
				retcode = delete_dellist(&dl, cnt);
			}
	} else {
modified src/delete.c
@@ -214,7 +214,7 @@ exec_delete(int argc, char **argv)
			goto cleanup;
		}
		rc = query_yesno(false,
-
		            "\nProceed with deinstalling packages? [y/N]: ");
+
		            "\nProceed with deinstalling packages? ");
	}
	else
		rc = yes;
modified src/fetch.c
@@ -204,11 +204,11 @@ exec_fetch(int argc, char **argv)

		if (rc != 0)
			rc = query_yesno(false, "\nProceed with fetching "
-
			    "packages? [y/N]: ");
+
			    "packages? ");
		else {
			printf("No packages are required to be fetched.\n");
			rc = query_yesno(false, "Check the integrity of packages "
-
							"downloaded? [y/N]: ");
+
							"downloaded? ");
			csum_only = true;
		}
	}
modified src/globals.c
@@ -23,6 +23,7 @@

#include <pkg.h>

+
int default_yes; /* Default always yes */
int yes; /* Assume always yes */
int dry_run; /* Do not perform any actions */
int auto_update; /* Do not update repo */
@@ -34,6 +35,7 @@ int newpkgversion; /* New package version is available */
void
set_globals(void)
{
+
	default_yes = pkg_object_bool(pkg_config_get("DEFAULT_ALWAYS_YES"));
	yes = pkg_object_bool(pkg_config_get("ASSUME_ALWAYS_YES"));
	dry_run = 0;
	auto_update = pkg_object_bool(pkg_config_get("REPO_AUTOUPDATE"));
modified src/install.c
@@ -232,7 +232,7 @@ exec_install(int argc, char **argv)

			if (!dry_run) {
				rc = query_yesno(false,
-
				    "\nProceed with this action? [y/N]: ");
+
				    "\nProceed with this action? ");
			}
			else {
				rc = false;
modified src/lock.c
@@ -61,7 +61,7 @@ do_lock(struct pkgdb *db, struct pkg *pkg)
		return (EPKG_OK);
	}

-
	if (!query_yesno(false, "%n-%v: lock this package? [y/N]: ",
+
	if (!query_yesno(false, "%n-%v: lock this package? ",
				 pkg, pkg))
		return (EPKG_OK);

@@ -81,7 +81,7 @@ do_unlock(struct pkgdb *db, struct pkg *pkg)
		return (EPKG_OK);
	}

-
	if (!query_yesno(false, "%n-%v: unlock this package? [y/N]: ",
+
	if (!query_yesno(false, "%n-%v: unlock this package? ",
				 pkg, pkg))
		return (EPKG_OK);

modified src/pkg.conf.sample
@@ -15,6 +15,7 @@
#INDEXDIR = "";
#INDEXFILE = "INDEX-10";        # Autogenerated
#HANDLE_RC_SCRIPTS = false;
+
#DEFAULT_ALWAYS_YES = false;
#ASSUME_ALWAYS_YES = false;
#REPOS_DIR [
#    "/etc/pkg/",
modified src/pkgcli.h
@@ -293,6 +293,7 @@ int analyse_query_string(char *qstr, struct query_flags *q_flags,
			 const unsigned int q_flags_len, int *flags,
			 char *multiline);

+
extern int default_yes;
extern int yes;
extern int dry_run;
extern int auto_update;
modified src/set.c
@@ -249,11 +249,11 @@ exec_set(int argc, char **argv)
		rc = yes;
		if (!yes) {
			if (pkg != NULL)
-
				rc = query_yesno(false, "Change %S from %S to %S for %n-%v? [y/N]: ",
+
				rc = query_yesno(false, "Change %S from %S to %S for %n-%v? ",
						changed, oldvalue, newvalue, pkg, pkg);
			else
-
				rc = query_yesno(false, "Change %S from %S to %S for all dependencies? "
-
						"[y/N]: ", changed, oldvalue, newvalue);
+
				rc = query_yesno(false, "Change %S from %S to %S for all dependencies? ",
+
						changed, oldvalue, newvalue);
		}
		if (pkg != NULL && rc) {
			if (pkgdb_set(db, pkg, field, newvalue) != EPKG_OK) {
@@ -280,11 +280,11 @@ exec_set(int argc, char **argv)
				if (!rc) {
					if (newautomatic)
						rc = query_yesno(false,
-
								"Mark %n-%v as automatically installed? [y/N]: ",
+
								"Mark %n-%v as automatically installed? ",
								pkg, pkg);
					else
						rc = query_yesno(false,
-
								"Mark %n-%v as not automatically installed? [y/N]: ",
+
								"Mark %n-%v as not automatically installed? ",
								pkg, pkg);
				}
				if (rc)
modified src/upgrade.c
@@ -187,7 +187,7 @@ exec_upgrade(int argc, char **argv)

			if (!dry_run)
				rc = query_yesno(false, "\nProceed with this "
-
				    "action? [y/N]: ");
+
				    "action? ");
			else
				rc = false;
		}
modified src/utils.c
@@ -63,26 +63,40 @@ query_tty_yesno(bool r, const char *msg, ...)
	int	 tty_fd;
	FILE	*tty;
	int	 tty_flags = O_RDWR;
+
	char	yesnomsg[1024];

#ifdef O_TTY_INIT
	tty_flags |= O_TTY_INIT;
#endif
	tty_fd = open(_PATH_TTY, tty_flags);
-
	if (tty_fd == -1)
-
		return (r);		/* No ctty -- return the
-
					 * default answer */
+
	if (tty_fd == -1) {
+
		/* No ctty -- return the default answer */
+
		if (default_yes)
+
			return (true);
+
		return (r);
+
	}

	tty = fdopen(tty_fd, "r+");

+
	strlcpy(yesnomsg, msg, sizeof(yesnomsg));
+
	if (default_yes || r)
+
		strlcat(yesnomsg, "[Y/n]: ", sizeof(yesnomsg));
+
	else
+
		strlcat(yesnomsg, "[y/N]: ", sizeof(yesnomsg));
+

	va_start(ap, msg);
-
	pkg_vfprintf(tty, msg, ap);
+
	pkg_vfprintf(tty, yesnomsg, ap);
	va_end(ap);

	c = getc(tty);
	if (c == 'y' || c == 'Y')
		r = true;
-
	else if (c == '\n' || c == EOF) {
+
	else if (c == 'n' || c == 'N')
		r = false;
+
	else if (c == '\n' || c == EOF) {
+
                if (default_yes)
+
			r = true;
+
		/* Else, r is not modified. It's default value is kept. */
		goto cleanup;
	}

@@ -103,22 +117,31 @@ vquery_yesno(bool deft, const char *msg, va_list ap)
	size_t linecap = 0;
	int linelen;
	bool	 r = deft;
+
	char	yesnomsg[1024];

	/* We use default value of yes or default in case of quiet mode */
	if (quiet)
-
		return (yes || r);
+
		return (yes || default_yes || r);

	/* Do not query user if we have specified yes flag */
	if (yes)
		return (true);

-
	pkg_vasprintf(&out, msg, ap);
+
	strlcpy(yesnomsg, msg, sizeof(yesnomsg));
+
	if (default_yes || r)
+
		strlcat(yesnomsg, "[Y/n]: ", sizeof(yesnomsg));
+
	else
+
		strlcat(yesnomsg, "[y/N]: ", sizeof(yesnomsg));
+

+
	pkg_vasprintf(&out, yesnomsg, ap);
	printf("%s", out);

	for (;;) {
		if ((linelen = getline(&line, &linecap, stdin)) != -1) {

			if (linelen == 1 && line[0] == '\n') {
+
				if (default_yes)
+
					r = true;
				break;
			}
			else if (linelen == 2) {
@@ -149,7 +172,9 @@ vquery_yesno(bool deft, const char *msg, va_list ap)
				continue;
			}
			else {
-
				/* Assume EOF as false */
+
				if (default_yes)
+
					r = true;
+
				/* Else, assume EOF as false */
				r = false;
				break;
			}
modified tests/frontend/pkg.shin
@@ -26,6 +26,7 @@ pkg_config_defaults_body()
	-o match:'^ *PKG_CACHEDIR = "/var/cache/pkg";$' \
	-o match:'^ *PORTSDIR = "/usr/ports";$' \
	-o match:'^ *HANDLE_RC_SCRIPTS = false;$' \
+
	-o match:'^ *DEFAULT_ALWAYS_YES = false;$' \
	-o match:'^ *ASSUME_ALWAYS_YES = false;$' \
	-o match:'^ *PLIST_KEYWORDS_DIR = "";$' \
	-o match:'^ *SYSLOG = true;$' \