Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Make 'pkg search' aware of multiple remote repositories
Marin Atanasov Nikolov committed 14 years ago
commit 206442c8c9a922e97c6ec58389cdbc6ac4db1738
parent 59bb7a8ec1cfae201b2665a626f27b86f938f20b
1 file changed +48 -26
modified pkg/search.c
@@ -1,3 +1,6 @@
+
#include <sys/param.h>
+

+
#include <err.h>
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
@@ -18,15 +21,16 @@ usage_search(void)
int
exec_search(int argc, char **argv)
{
-
	char *pattern;
+
	char *pattern = NULL;
	match_t match = MATCH_EXACT;
	int  retcode = EPKG_OK;
	unsigned int field = REPO_SEARCH_NAME;
	int ch;
-
	char size[7];
+
	char size[7], dbfile[MAXPATHLEN];
	struct pkgdb *db = NULL;
	struct pkgdb_it *it = NULL;
	struct pkg *pkg = NULL;
+
	struct pkg_remote_repo *repo = NULL;

	while ((ch = getopt(argc, argv, "gxXcd")) != -1) {
		switch (ch) {
@@ -61,34 +65,52 @@ exec_search(int argc, char **argv)

	pattern = argv[0];

-
	if (pkgdb_open(&db, PKGDB_REMOTE, "repo.sqlite") != EPKG_OK) {
-
		retcode = EPKG_FATAL;
-
		goto cleanup;
-
	}
+
	pkg_remote_repo_init();
+
	pkg_remote_repo_load();

-
	if ((it = pkgdb_rquery(db, pattern, match, field)) == NULL) {
-
		retcode = EPKG_FATAL;
-
		goto cleanup;
-
	}

-
	while (( retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
-
		printf("Name: %s\n", pkg_get(pkg, PKG_NAME));
-
		printf("Version: %s\n", pkg_get(pkg, PKG_VERSION));
-
		printf("Origin: %s\n", pkg_get(pkg, PKG_ORIGIN));
-
		printf("Maintainer: %s\n", pkg_get(pkg, PKG_MAINTAINER));
-
		printf("WWW: %s\n", pkg_get(pkg, PKG_WWW));
-
		printf("Comment: %s\n", pkg_get(pkg, PKG_COMMENT));
-
		humanize_number(size, sizeof(size), pkg_new_flatsize(pkg), "B", HN_AUTOSCALE, 0);
-
		printf("Flat size: %s\n", size);
-
		humanize_number(size, sizeof(size), pkg_new_pkgsize(pkg), "B", HN_AUTOSCALE, 0);
-
		printf("Pkg size: %s\n", size);
-
		printf("\n");
+
	/*
+
	 * TODO: Implement a feature to search only
+
	 * in a given repository instead of all
+
	 */
+
	while ((repo = pkg_remote_repo_next()) != NULL) {
+
		snprintf(dbfile, MAXPATHLEN, "%s.sqlite", repo->name);
+

+
		if ((retcode = pkgdb_open(&db, PKGDB_REMOTE, dbfile)) != EPKG_OK) {
+
			warnx("cannot open repository database: %s/%s\n", 
+
					pkg_config("PKG_DBDIR"), dbfile);
+
			warnx("skipping repository %s\n", repo->name);
+
			pkgdb_close(db);
+
			continue;
+
		}
+

+
		if ((it = pkgdb_rquery(db, pattern, match, field)) == NULL) {
+
			warnx("cannot query repository database: %s/%s\n",
+
					pkg_config("PKG_DBDIR"), dbfile);
+
			warnx("skipping repository %s\n", repo->name);
+
			pkgdb_it_free(it);
+
			pkgdb_close(db);
+
			continue;
+
		}
+

+
		while ((retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
+
			printf("Name:       %s\n", pkg_get(pkg, PKG_NAME));
+
			printf("Version:    %s\n", pkg_get(pkg, PKG_VERSION));
+
			printf("Origin:     %s\n", pkg_get(pkg, PKG_ORIGIN));
+
			printf("Arch:       %s\n", pkg_get(pkg, PKG_ARCH));
+
			printf("Maintainer: %s\n", pkg_get(pkg, PKG_MAINTAINER));
+
			printf("WWW:        %s\n", pkg_get(pkg, PKG_WWW));
+
			printf("Comment:    %s\n", pkg_get(pkg, PKG_COMMENT));
+
			printf("Repository: %s\n", repo->name);
+
			humanize_number(size, sizeof(size), pkg_new_flatsize(pkg), "B", HN_AUTOSCALE, 0);
+
			printf("Flat size:  %s\n", size);
+
			humanize_number(size, sizeof(size), pkg_new_pkgsize(pkg), "B", HN_AUTOSCALE, 0);
+
			printf("Pkg size:   %s\n", size);
+
			printf("\n");
+
		}
	}

-
	cleanup:
-
	pkgdb_it_free(it);
-
	pkgdb_close(db);
+
	pkg_remote_repo_free();

	return (retcode);
-

}