xbps-repo: implement new target 'pkg-list' to list pkgs from target repo.
This commit is contained in:
		
							
								
								
									
										4
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								NEWS
									
									
									
									
									
								
							@@ -1,5 +1,9 @@
 | 
			
		||||
xbps-0.11.0 (???):
 | 
			
		||||
 | 
			
		||||
 * xbps-repo(8): new target: pkg-list [index]. This target will list all
 | 
			
		||||
   packages from repository with index [index]. If optional argument
 | 
			
		||||
   [index] (decimal) not set, all repositories will be used.
 | 
			
		||||
 | 
			
		||||
 * libxbps: when registering new packages, existing entries in
 | 
			
		||||
   requiredby matching the same pkgname/version touple are now
 | 
			
		||||
   simply skipped.
 | 
			
		||||
 
 | 
			
		||||
@@ -41,6 +41,7 @@ struct xferstat {
 | 
			
		||||
struct list_pkgver_cb {
 | 
			
		||||
	pkg_state_t state;
 | 
			
		||||
	size_t pkgver_len;
 | 
			
		||||
	bool check_state;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* from transaction.c */
 | 
			
		||||
 
 | 
			
		||||
@@ -43,17 +43,18 @@ list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done)
 | 
			
		||||
 | 
			
		||||
	(void)loop_done;
 | 
			
		||||
 | 
			
		||||
	if (xbps_pkg_state_dictionary(obj, &curstate))
 | 
			
		||||
		return EINVAL;
 | 
			
		||||
 | 
			
		||||
	if (lpc->state == 0) {
 | 
			
		||||
		/* Only list packages that are fully installed */
 | 
			
		||||
		if (curstate != XBPS_PKG_STATE_INSTALLED)
 | 
			
		||||
			return 0;
 | 
			
		||||
	} else {
 | 
			
		||||
		/* Only list packages with specified state */
 | 
			
		||||
		if (curstate != lpc->state)
 | 
			
		||||
			return 0;
 | 
			
		||||
	if (lpc->check_state) {
 | 
			
		||||
		if (xbps_pkg_state_dictionary(obj, &curstate))
 | 
			
		||||
			return EINVAL;
 | 
			
		||||
		if (lpc->state == 0) {
 | 
			
		||||
			/* Only list packages that are fully installed */
 | 
			
		||||
			if (curstate != XBPS_PKG_STATE_INSTALLED)
 | 
			
		||||
				return 0;
 | 
			
		||||
		} else {
 | 
			
		||||
			/* Only list packages with specified state */
 | 
			
		||||
			if (curstate != lpc->state)
 | 
			
		||||
				return 0;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
 | 
			
		||||
 
 | 
			
		||||
@@ -198,6 +198,7 @@ main(int argc, char **argv)
 | 
			
		||||
			goto out;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		lpc.check_state = true;
 | 
			
		||||
		lpc.state = 0;
 | 
			
		||||
		if (argv[1]) {
 | 
			
		||||
			if (strcmp(argv[1], "installed") == 0)
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ TOPDIR = ../..
 | 
			
		||||
BIN =	xbps-repo
 | 
			
		||||
OBJS =	main.o index.o show.o find-files.o
 | 
			
		||||
OBJS += ../xbps-bin/fetch_cb.o ../xbps-bin/util.o
 | 
			
		||||
OBJS += ../xbps-bin/state_cb.o
 | 
			
		||||
OBJS += ../xbps-bin/state_cb.o ../xbps-bin/list.o
 | 
			
		||||
MAN = $(BIN).8
 | 
			
		||||
 | 
			
		||||
include $(TOPDIR)/bin/prog.mk
 | 
			
		||||
 
 | 
			
		||||
@@ -50,6 +50,30 @@ usage(struct xbps_handle *xhp)
 | 
			
		||||
	exit(EXIT_FAILURE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
repo_pkg_list_cb(struct repository_pool_index *rpi, void *arg, bool *done)
 | 
			
		||||
{
 | 
			
		||||
	struct list_pkgver_cb lpc;
 | 
			
		||||
	uint16_t idx;
 | 
			
		||||
	char *cp;
 | 
			
		||||
 | 
			
		||||
	(void)done;
 | 
			
		||||
	if (arg != NULL) {
 | 
			
		||||
		idx = (uint16_t)strtoul(arg, &cp, 0);
 | 
			
		||||
		if (rpi->rpi_index != idx)
 | 
			
		||||
			return 0;
 | 
			
		||||
	}
 | 
			
		||||
	lpc.check_state = false;
 | 
			
		||||
	lpc.state = 0;
 | 
			
		||||
	lpc.pkgver_len = find_longest_pkgver(rpi->rpi_repod);
 | 
			
		||||
 | 
			
		||||
	printf("From %s repository ...\n", rpi->rpi_uri);
 | 
			
		||||
	(void)xbps_callback_array_iter_in_dict(rpi->rpi_repod,
 | 
			
		||||
	    "packages", list_pkgs_in_dict, &lpc);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
repo_list_uri_cb(struct repository_pool_index *rpi, void *arg, bool *done)
 | 
			
		||||
{
 | 
			
		||||
@@ -62,8 +86,8 @@ repo_list_uri_cb(struct repository_pool_index *rpi, void *arg, bool *done)
 | 
			
		||||
	prop_dictionary_get_cstring_nocopy(rpi->rpi_repod,
 | 
			
		||||
	    "pkgindex-version", &pkgidx);
 | 
			
		||||
	prop_dictionary_get_uint64(rpi->rpi_repod, "total-pkgs", &npkgs);
 | 
			
		||||
	printf("%s (index %s, " "%" PRIu64 " packages)\n",
 | 
			
		||||
	    rpi->rpi_uri, pkgidx, npkgs);
 | 
			
		||||
	printf("[%u] %s (index %s, " "%" PRIu64 " packages)\n",
 | 
			
		||||
	    rpi->rpi_index, rpi->rpi_uri, pkgidx, npkgs);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
@@ -166,7 +190,20 @@ main(int argc, char **argv)
 | 
			
		||||
		else if (rv != 0 && rv != ENOTSUP)
 | 
			
		||||
			xbps_error_printf("xbps-repo: failed to initialize "
 | 
			
		||||
			    "rpool: %s\n", strerror(rv));
 | 
			
		||||
	} else if (strcasecmp(argv[0], "pkg-list") == 0) {
 | 
			
		||||
		/*
 | 
			
		||||
		 * Only list packages for the target repository.
 | 
			
		||||
		 */
 | 
			
		||||
		if (argc < 1 || argc > 2)
 | 
			
		||||
			usage(xhp);
 | 
			
		||||
 | 
			
		||||
		rv = xbps_repository_pool_foreach(repo_pkg_list_cb, argv[1]);
 | 
			
		||||
		if (rv == ENOTSUP)
 | 
			
		||||
			xbps_error_printf("xbps-repo: no repositories "
 | 
			
		||||
			    "currently registered!\n");
 | 
			
		||||
		else if (rv != 0)
 | 
			
		||||
			xbps_error_printf("xbps-repo: failed to initialize "
 | 
			
		||||
			    "rpool: %s\n", strerror(rv));
 | 
			
		||||
	} else if (strcasecmp(argv[0], "search") == 0) {
 | 
			
		||||
		/*
 | 
			
		||||
		 * Search for a package by looking at pkgname/short_desc
 | 
			
		||||
@@ -182,7 +219,6 @@ main(int argc, char **argv)
 | 
			
		||||
		else if (rv != 0 && rv != ENOTSUP)
 | 
			
		||||
			xbps_error_printf("xbps-repo: failed to initialize "
 | 
			
		||||
			    "rpool: %s\n", strerror(rv));
 | 
			
		||||
 | 
			
		||||
	} else if (strcasecmp(argv[0], "show") == 0) {
 | 
			
		||||
		/* Shows info about a binary package. */
 | 
			
		||||
		if (argc != 2)
 | 
			
		||||
@@ -199,7 +235,6 @@ main(int argc, char **argv)
 | 
			
		||||
			xbps_error_printf("xbps-repo: unexpected error '%s' ",
 | 
			
		||||
			    "searching for '%s'\n", strerror(rv), argv[1]);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	} else if (strcasecmp(argv[0], "show-deps") == 0) {
 | 
			
		||||
		/* Shows the required run dependencies for a package. */
 | 
			
		||||
		if (argc != 2)
 | 
			
		||||
@@ -216,7 +251,6 @@ main(int argc, char **argv)
 | 
			
		||||
			xbps_error_printf("xbps-repo: unexpected error '%s' "
 | 
			
		||||
			    "searching for '%s'\n", strerror(errno), argv[1]);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	} else if (strcasecmp(argv[0], "show-files") == 0) {
 | 
			
		||||
		/* Shows the package files in a binary package */
 | 
			
		||||
		if (argc != 2)
 | 
			
		||||
@@ -241,7 +275,6 @@ main(int argc, char **argv)
 | 
			
		||||
		}
 | 
			
		||||
		rv = show_pkg_files(pkgd);
 | 
			
		||||
		prop_object_release(pkgd);
 | 
			
		||||
 | 
			
		||||
	} else if (strcasecmp(argv[0], "find-files") == 0) {
 | 
			
		||||
		/* Finds files by patterns, exact matches and components. */
 | 
			
		||||
		if (argc != 2)
 | 
			
		||||
@@ -252,14 +285,12 @@ main(int argc, char **argv)
 | 
			
		||||
			xbps_error_printf("xbps-repo: no repositories "
 | 
			
		||||
			    "currently registered!\n");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	} else if (strcasecmp(argv[0], "genindex") == 0) {
 | 
			
		||||
		/* Generates a package repository index plist file. */
 | 
			
		||||
		if (argc != 2)
 | 
			
		||||
			usage(xhp);
 | 
			
		||||
 | 
			
		||||
		rv = repo_genindex(argv[1]);
 | 
			
		||||
 | 
			
		||||
	} else if (strcasecmp(argv[0], "sync") == 0) {
 | 
			
		||||
		/* Syncs the pkg index for all registered remote repos */
 | 
			
		||||
		if (argc != 1)
 | 
			
		||||
@@ -270,7 +301,6 @@ main(int argc, char **argv)
 | 
			
		||||
			xbps_error_printf("xbps-repo: no repositories "
 | 
			
		||||
			    "currently registered!\n");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	} else {
 | 
			
		||||
		usage(xhp);
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -94,6 +94,13 @@ will be removed automatically\&.
 | 
			
		||||
Lists all working repositories in repository pool\&.
 | 
			
		||||
.RE
 | 
			
		||||
.PP
 | 
			
		||||
\fBpkg\-list [\fR\fB\fIindex\fR\fR\fB]\fR
 | 
			
		||||
.RS 4
 | 
			
		||||
Lists all currently registered packages in repository index as specified in the \fIindex\fR argument.
 | 
			
		||||
If argument is not specified, all repositories will be used to list packages\&. The argument
 | 
			
		||||
expects a decimal number starting from 0, matching the output of the \fIlist\fR target.
 | 
			
		||||
.RE
 | 
			
		||||
.PP
 | 
			
		||||
\fBsearch\fR \fIpattern\fR
 | 
			
		||||
.RS 4
 | 
			
		||||
Search for packages containing the shell
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,7 @@
 | 
			
		||||
 */
 | 
			
		||||
#define XBPS_PKGINDEX_VERSION	"1.3"
 | 
			
		||||
 | 
			
		||||
#define XBPS_API_VERSION	"20111130"
 | 
			
		||||
#define XBPS_API_VERSION	"20111203"
 | 
			
		||||
#define XBPS_VERSION		"0.11.0"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -1285,6 +1285,12 @@ struct repository_pool_index {
 | 
			
		||||
	 * URI string associated with repository.
 | 
			
		||||
	 */
 | 
			
		||||
	char *rpi_uri;
 | 
			
		||||
	/**
 | 
			
		||||
	 * @var rpi_index
 | 
			
		||||
	 *
 | 
			
		||||
	 * Repository index in pool.
 | 
			
		||||
	 */
 | 
			
		||||
	uint16_t rpi_index;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 
 | 
			
		||||
@@ -79,7 +79,7 @@ xbps_repository_pool_init(void)
 | 
			
		||||
	prop_string_t obj;
 | 
			
		||||
	struct xbps_handle *xhp;
 | 
			
		||||
	struct repository_pool *rpool;
 | 
			
		||||
	size_t i, ntotal = 0, nmissing = 0;
 | 
			
		||||
	size_t i, ntotal = 0, nmissing = 0, repocnt = 0;
 | 
			
		||||
	const char *repouri;
 | 
			
		||||
	char *plist;
 | 
			
		||||
	int rv = 0;
 | 
			
		||||
@@ -178,7 +178,9 @@ xbps_repository_pool_init(void)
 | 
			
		||||
		}
 | 
			
		||||
		free(plist);
 | 
			
		||||
		xbps_dbg_printf("[rpool] `%s' registered.\n", repouri);
 | 
			
		||||
		rpool->rpi->rpi_index = repocnt;
 | 
			
		||||
		SIMPLEQ_INSERT_TAIL(&rpool_queue, rpool, rp_entries);
 | 
			
		||||
		repocnt++;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (ntotal - nmissing == 0) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user