Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
install can now take glob, regex, it can match on name, name-version and origin
Baptiste Daroussin committed 14 years ago
commit 0c8a9c09469e95e29312f577d8afaa33cda62e3d
parent 3a66d66
3 files changed +37 -18
modified libpkg/pkg_add.c
@@ -4,7 +4,6 @@
#include <archive_entry.h>
#include <assert.h>
#include <libgen.h>
-
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <fnmatch.h>
@@ -82,7 +81,7 @@ do_extract(struct archive *a, struct archive_entry *ae)
int
pkg_add(struct pkgdb *db, const char *path)
{
-
	return (pkg_add2(db, path, false));
+
	return (pkg_add2(db, path, 0));
}

int
modified pkg/event.c
@@ -50,6 +50,9 @@ event_callback(void *data __unused, struct pkg_event *ev)
				pkg_get(ev->e_upgrade_finished.pkg, PKG_VERSION),
				pkg_get(ev->e_upgrade_finished.pkg, PKG_NEWVERSION));
		break;
+
	case PKG_EVENT_UPGRADE_FINISHED:
+
		printf("done\n");
+
		break;
	case PKG_EVENT_REQUIRED:
		pkg = ev->e_required.pkg;
		fprintf(stderr, "%s-%s is required by:", pkg_get(pkg, PKG_NAME),
modified pkg/install.c
@@ -16,7 +16,7 @@
void
usage_install(void)
{
-
	fprintf(stderr, "usage: pkg install [-y] <pkg-name> <...>\n");
+
	fprintf(stderr, "usage: pkg install [-ygxXf] <pkg-name> <...>\n");
	fprintf(stderr, "For more information see 'pkg help install'.\n");
}

@@ -24,33 +24,45 @@ int
exec_install(int argc, char **argv)
{
	struct pkg *pkg = NULL;
+
	struct pkgdb_it *it;
	struct pkgdb *db = NULL;
	struct pkg_jobs *jobs = NULL;
	int retcode = EPKG_OK;
	int i, ch, yes = 0;
+
	match_t match = MATCH_EXACT;

-
	if (argc < 2) {
-
		usage_install();
-
		return (EX_USAGE);
-
	}
-

-
	if (geteuid() != 0) {
-
		warnx("installing packages can only be done as root");
-
		return (EX_NOPERM);
-
	}
-

-
	while ((ch = getopt(argc, argv, "y")) != -1) {
+
	while ((ch = getopt(argc, argv, "ygxXf")) != -1) {
		switch (ch) {
			case 'y':
				yes = 1;
				break;
-
			default:
+
			case 'g':
+
				match = MATCH_GLOB;
				break;
+
			case 'x':
+
				match = MATCH_REGEX;
+
				break;
+
			case 'X':
+
				match = MATCH_EREGEX;
+
				break;
+
			default:
+
				usage_install();
+
				return (EX_USAGE);
		}
	}
	argc -= optind;
	argv += optind;

+
	if (argc < 1) {
+
		usage_install();
+
		return (EX_USAGE);
+
	}
+

+
	if (geteuid() != 0) {
+
		warnx("installing packages can only be done as root");
+
		return (EX_NOPERM);
+
	}
+

	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {
		return (EX_IOERR);
	}
@@ -61,12 +73,15 @@ exec_install(int argc, char **argv)
	}

	for (i = 0; i < argc; i++) {
-
		if ((pkg = pkgdb_query_remote(db, argv[i])) == NULL) {
+
		if ((it = pkgdb_rquery(db, argv[i], match, REPO_SEARCH_NAME)) == NULL) {
			retcode = EPKG_FATAL;
			goto cleanup;
		}

-
		pkg_jobs_add(jobs, pkg);
+
		while (( retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
+
			pkg_jobs_add(jobs, pkgdb_query_remote(db, pkg_get(pkg, PKG_ORIGIN)));
+
		}
+

	}

	/* print a summary before applying the jobs */
@@ -75,7 +90,7 @@ exec_install(int argc, char **argv)
	while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
		printf("\t%s-%s\n", pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION));
	}
-

+
 
	if (yes == 0)
		yes = query_yesno("\nProceed with installing packages [y/N]: ");

@@ -85,6 +100,8 @@ exec_install(int argc, char **argv)
	cleanup:
	
	pkg_jobs_free(jobs);
+
	pkgdb_it_free(it);
+
	pkg_free(pkg);
	pkgdb_close(db);

	return (retcode == EPKG_OK ? EX_OK : 1);