Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add -f and -q options to pkg-add.
Vsevolod Stakhov committed 13 years ago
commit 2d018ea396e586a60907acbcbde4b86fa689a910
parent 3ccbe75
3 files changed +29 -9
modified libpkg/pkg_add.c
@@ -154,6 +154,7 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags)
	const char	*arch;
	const char	*myarch;
	const char	*origin;
+
	const char	*name;
	struct archive	*a;
	struct archive_entry *ae;
	struct pkg	*pkg = NULL;
@@ -199,7 +200,7 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags)
	 */

	pkg_config_string(PKG_CONFIG_ABI, &myarch);
-
	pkg_get(pkg, PKG_ARCH, &arch, PKG_ORIGIN, &origin);
+
	pkg_get(pkg, PKG_ARCH, &arch, PKG_ORIGIN, &origin, PKG_NAME, &name);

	if (fnmatch(myarch, arch, FNM_CASEFOLD) == FNM_NOMATCH &&
	    strncmp(arch, myarch, strlen(myarch)) != 0) {
@@ -217,9 +218,18 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags)

	ret = pkg_try_installed(db, origin, &pkg_inst, PKG_LOAD_BASIC);
	if (ret == EPKG_OK) {
-
		pkg_emit_already_installed(pkg_inst);
-
		retcode = EPKG_INSTALLED;
-
		goto cleanup;
+
		if ((flags & PKG_FLAG_FORCE) == 0) {
+
			pkg_emit_already_installed(pkg_inst);
+
			retcode = EPKG_INSTALLED;
+
			pkg_free(pkg_inst);
+
			goto cleanup;
+
		}
+
		else {
+
			pkg_emit_notice("package %s is already installed, forced install", name);
+
			/* We need to upgrade package, so set appropriate flag */
+
			flags |= PKG_ADD_UPGRADE;
+
			pkg_free(pkg_inst);
+
		}
	} else if (ret != EPKG_END) {
		retcode = ret;
		goto cleanup;
modified pkg/add.c
@@ -54,8 +54,8 @@ is_url(const char * const pattern)
void
usage_add(void)
{
-
	fprintf(stderr, "usage: pkg add [-IA] <pkg-name> ...\n");
-
	fprintf(stderr, "       pkg add [-IA] <protocol>://<path>/<pkg-name> ...\n\n");
+
	fprintf(stderr, "usage: pkg add [-IAfq] <pkg-name> ...\n");
+
	fprintf(stderr, "       pkg add [-IAfq] <protocol>://<path>/<pkg-name> ...\n\n");
	fprintf(stderr, "For more information see 'pkg help add'.\n");
}

@@ -72,7 +72,7 @@ exec_add(int argc, char **argv)
	int failedpkgcount = 0;
	pkg_flags f = PKG_FLAG_NONE;

-
	while ((ch = getopt(argc, argv, "IA")) != -1) {
+
	while ((ch = getopt(argc, argv, "IAfq")) != -1) {
		switch (ch) {
		case 'I':
			f |= PKG_ADD_NOSCRIPT;
@@ -80,6 +80,12 @@ exec_add(int argc, char **argv)
		case 'A':
			f |= PKG_FLAG_AUTOMATIC;
			break;
+
		case 'f':
+
			f |= PKG_FLAG_FORCE;
+
			break;
+
		case 'q':
+
			quiet = true;
+
			break;
		default:
			usage_add();
			return (EX_USAGE);
modified pkg/pkg-add.8
@@ -23,10 +23,10 @@
.Nd Registers a package and installs it on the system
.Sh SYNOPSIS
.Nm
-
.Op Fl IA
+
.Op Fl IAfq
.Ar <pkg-name> ...
.Nm
-
.Op Fl IA
+
.Op Fl IAfq
.Ar <protocol>://<path>/<pkg-name> ...
.Sh DESCRIPTION
.Nm
@@ -48,6 +48,10 @@ Mark the installed packages as orphan.
Will be automatically removed if no other packages depend on them.
For more information please refer to
.Xr pkg-autoremove 8
+
.It Fl f
+
Force the reinstallation of the package if already installed.
+
.It Fl q
+
Force quiet output.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of