Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add new pkgdb_open_all() -- same as pkgdb_open(), but allows specifying the pkg repository to use as the 'reponame' arg. If 'reponame' is NULL, is identical to pkgdb_open()
Matthew Seaman committed 12 years ago
commit 7794a36ef600d862598e6ec22f62672abd2ba2ee
parent 2629151
16 files changed +123 -54
modified docs/pkg-install.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd March 21, 2014
+
.Dd April 13, 2014
.Dt PKG-INSTALL 8
.Os
.Sh NAME
@@ -142,10 +142,11 @@ When used with
.Fl f ,
reinstalls any packages that require the given package.
.It Fl r Ar reponame
-
In multi-repo mode, override the
-
.Fa pkg.conf
-
ordering and only attempt to download packages from the named
-
repository.
+
Install packages from only the named repository,
+
irrespective of the configured
+
.Dq active
+
status from
+
.Pa repo.conf .
.It Fl U
Skip updating the repository catalogues with
.Xr pkg-update 8 .
modified docs/pkg-rquery.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd February 1, 2014
+
.Dd April 13, 2014
.Dt PKG-RQUERY 8
.Os
.Sh NAME
@@ -57,11 +57,14 @@ Match packages using the given
.Ar evaluation-condition.
See EVALUATION FORMAT for details.
.It Fl r Ar reponame
-
Fetches packages from the given
-
.Ar reponame
-
if multiple repo support is enabled.
-
See
-
.Xr pkg.conf 5 .
+
Query for data about packages from only the named repository,
+
irrespective of the configured
+
.Dq active
+
status from
+
.Pa repo.conf .
+
By default all repository catalogues marked
+
.Dq active
+
are queried.
.It Fl g
Treat
.Ao pattern Ac
modified docs/pkg-search.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd November 29, 2013
+
.Dd April 13, 2014
.Dt PKG-SEARCH 8
.Os
.Sh NAME
@@ -24,14 +24,14 @@
.Sh SYNOPSIS
.Nm
.Op Fl egix
-
.Op Fl r Ar repo
+
.Op Fl r Ar reponame
.Op Fl S Ar search
.Op Fl L Ar label
.Op Fl Q Ar query-modifier
.Ar pattern
.Nm
.Op Fl cDdefgiopqRx
-
.Op Fl r Ar repo
+
.Op Fl r Ar reponame
.Ar pattern
.Sh DESCRIPTION
.Nm
@@ -132,13 +132,17 @@ flags.
See the
.Qq Sx Output Modifier Options
section for details.
-
.It Fl r Ar repo
-
Select only the repository catalogue named as
-
.Sy repo
-
to search.
-
By default all configured repository catalogues are searched.
+
.It Fl r Ar reponame
+
Search for packages from only the named repository,
+
irrespective of the configured
+
.Dq active
+
status from
+
.Pa repo.conf .
+
By default all repository catalogues marked
+
.Dq active
+
are searched.
.It Fl R
-
Display the full manifest (raw) about the packages matching.
+
Display the full manifest (raw) from the matching packages.
.It Fl S Ar search
Specify the field to search the repository catalogue on.
If unspecified, searches on
modified docs/pkg-update.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd August 12, 2013
+
.Dd April 13, 2014
.Dt PKG-UPDATE 8
.Os
.Sh NAME
@@ -25,6 +25,7 @@ package repositories
.Sh SYNOPSIS
.Nm
.Op Fl fq
+
.Op Fl r Ar reponame
.Sh DESCRIPTION
.Nm
is used for updating the local copy of a repository catalogue from
@@ -74,6 +75,12 @@ Force quiet output
.It Fl f
Force a full download of the repository catalogue without regard to the
respective ages of the local and remote copies of the catalogue
+
.It Fl r Ar reponame
+
Download the catalogue for the named repository only.
+
This will update only the named repository, irrespective of the configured
+
.Dq active
+
status from
+
.Pa repo.conf .
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
modified docs/pkg-upgrade.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd June 30, 2013
+
.Dd April 13, 2014
.Dt PKG-UPGRADE 8
.Os
.Sh NAME
@@ -127,6 +127,12 @@ Skip updating the repository catalogues with
Use the local cache only.
.Nm
will always print out the list of packages with available updates.
+
.It Fl r Ar reponame
+
Install packages from only the named repository,
+
irrespective of the configured
+
.Dq active
+
status from
+
.Pa repo.conf .
.It Fl y
Assume yes when asked for confirmation before package installation.
.El
modified docs/pkg-version.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd March 30, 2014
+
.Dd April 13, 2014
.Dt PKG-VERSION 8
.Os
.Sh NAME
@@ -109,9 +109,16 @@ This only has any effect in combination with the
.Fl R
option.
.It Fl r Ar reponame
-
Use the given
-
.Ar reponame
-
for comparison when using
+
When using
+
.Fl R
+
compare installed package versions to packages available from the
+
named repository only, irrespective of the configured
+
.Dq active
+
status from
+
.Pa repo.conf .
+
By default all repository catalogues marked
+
.Dq active
+
are used for version comparisons.
.Fl R
.It Fl o
Display package origin, instead of package name.
modified libpkg/pkg.h.in
@@ -992,6 +992,14 @@ int pkgdb_access(unsigned mode, unsigned database);
int pkgdb_open(struct pkgdb **db, pkgdb_t type);

/**
+
 * Open the local package database and repositories, possibly
+
 * overriding configured repositories and replacing with the given
+
 * reponame if not NULL
+
 * @return An error code
+
 */
+
int pkgdb_open_all(struct pkgdb **db, pkgdb_t type, const char *reponame);
+

+
/**
 * Locking functions
 */
int pkgdb_obtain_lock(struct pkgdb *db, pkgdb_lock_t type, double delay, unsigned int retries);
modified libpkg/pkgdb.c
@@ -779,7 +779,8 @@ pkgdb_remote_init(struct pkgdb *db, const char *repo)
}

static int
-
pkgdb_open_multirepos(const char *dbdir, struct pkgdb *db)
+
pkgdb_open_multirepos(const char *dbdir, struct pkgdb *db,
+
		      const char *reponame)
{
	int		  ret;
	char		  remotepath[MAXPATHLEN];
@@ -787,8 +788,13 @@ pkgdb_open_multirepos(const char *dbdir, struct pkgdb *db)
	int		  repocount = 0;

	while (pkg_repos(&r) == EPKG_OK) {
-
		if (!pkg_repo_enabled(r))
-
			continue;
+
		if (reponame != NULL) {
+
			if (strcmp(pkg_repo_ident(r), reponame) != 0)
+
				continue;
+
		} else {
+
			if (!pkg_repo_enabled(r)) 
+
				continue;
+
		}

		/* is it already attached? */
		if (pkgdb_is_attached(db->sqlite, pkg_repo_name(r))) {
@@ -1030,6 +1036,12 @@ pkgdb_access(unsigned mode, unsigned database)
int
pkgdb_open(struct pkgdb **db_p, pkgdb_t type)
{
+
	return (pkgdb_open_all(db_p, type, NULL));
+
}
+

+
int
+
pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)
+
{
	struct pkgdb	*db = NULL;
	struct statfs	 stfs;
	bool		 reopen = false;
@@ -1134,17 +1146,17 @@ pkgdb_open(struct pkgdb **db_p, pkgdb_t type)
	}

	if (type == PKGDB_REMOTE || type == PKGDB_MAYBE_REMOTE) {
-
		if (pkg_repos_activated_count() > 0) {
+
		if (reponame != NULL || pkg_repos_activated_count() > 0) {
			db->type = PKGDB_REMOTE;
-
			if ((ret = pkgdb_open_multirepos(dbdir, db)) != EPKG_OK)
+
			ret = pkgdb_open_multirepos(dbdir, db, reponame);
+
			if (ret != EPKG_OK)
				return (ret);
		} else if (type == PKGDB_REMOTE) {
			if (*db_p == NULL)
				pkgdb_close(db);
-
			pkg_emit_error("No activated remote repositories configured");
+
			pkg_emit_error("No active remote repositories configured");
			return (EPKG_FATAL);
		}
-

	}

	*db_p = db;
modified src/fetch.c
@@ -145,10 +145,11 @@ exec_fetch(int argc, char **argv)
	}

	/* first update the remote repositories if needed */
-
	if (auto_update && (retcode = pkgcli_update(false)) != EPKG_OK)
+
	if (auto_update &&
+
	    (retcode = pkgcli_update(false, reponame)) != EPKG_OK)
		return (retcode);

-
	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK)
+
	if (pkgdb_open_all(&db, PKGDB_REMOTE, reponame) != EPKG_OK)
		return (EX_IOERR);

	if (pkgdb_obtain_lock(db, PKGDB_LOCK_READONLY, 0, 0) != EPKG_OK) {
modified src/install.c
@@ -173,10 +173,13 @@ exec_install(int argc, char **argv)
		retcode = EX_SOFTWARE;

	/* first update the remote repositories if needed */
-
	if (auto_update && (updcode = pkgcli_update(false)) != EPKG_OK)
+
	if (auto_update &&
+
	    (updcode = pkgcli_update(false, reponame)) != EPKG_OK)
		return (updcode);

-
	if (pkgdb_open(&db, local_only ? PKGDB_DEFAULT : PKGDB_MAYBE_REMOTE) != EPKG_OK)
+
	if (pkgdb_open_all(&db,
+
	    local_only ? PKGDB_DEFAULT : PKGDB_MAYBE_REMOTE,
+
	    reponame) != EPKG_OK)
		return (EX_IOERR);

	if (pkgdb_obtain_lock(db, lock_type, 0, 0) != EPKG_OK) {
modified src/pkgcli.h
@@ -128,7 +128,7 @@ void usage_stats(void);
/* pkg update */
int exec_update(int, char **);
void usage_update(void);
-
int pkgcli_update(bool);
+
int pkgcli_update(bool, const char *);

/* pkg updating */
int exec_updating(int, char **);
modified src/rquery.c
@@ -193,11 +193,11 @@ exec_rquery(int argc, char **argv)
	/* first update the remote repositories if needed */
	old_quiet = quiet;
	quiet = true;
-
	if (auto_update && (ret = pkgcli_update(false)) != EPKG_OK)
+
	if (auto_update && (ret = pkgcli_update(false, reponame)) != EPKG_OK)
		return (ret);
	quiet = old_quiet;

-
	ret = pkgdb_open(&db, PKGDB_REMOTE);
+
	ret = pkgdb_open_all(&db, PKGDB_REMOTE, reponame);
	if (ret != EPKG_OK)
		return (EX_IOERR);

modified src/search.c
@@ -371,11 +371,11 @@ exec_search(int argc, char **argv)
	/* first update the remote repositories if needed */
	old_quiet = quiet;
	quiet = true;
-
	if (auto_update && (ret = pkgcli_update(false)) != EPKG_OK)
+
	if (auto_update && (ret = pkgcli_update(false, reponame)) != EPKG_OK)
		return (ret);
	quiet = old_quiet;

-
	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK)
+
	if (pkgdb_open_all(&db, PKGDB_REMOTE, reponame) != EPKG_OK)
		return (EX_IOERR);

	if ((it = pkgdb_search(db, pattern, match, search, search,
modified src/update.c
@@ -2,6 +2,7 @@
 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
+
 * Copyright (c) 2014 Matthew Seaman <matthew@FreeBSD.org>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
@@ -44,7 +45,8 @@
 * Fetch repository calalogues.
 */
int
-
pkgcli_update(bool force) {
+
pkgcli_update(bool force, const char *reponame)
+
{
	int retcode = EPKG_FATAL, update_count = 0;
	struct pkg_repo *r = NULL;

@@ -53,8 +55,13 @@ pkgcli_update(bool force) {
	    PKGDB_DB_REPO) == EPKG_ENOACCESS)
		return (EPKG_OK);

-
	if (!quiet)
-
		printf("Updating repository catalogue\n");
+
	if (!quiet) {
+
		if (reponame != NULL)
+
			printf("Updating \"%s\" repository catalogue\n",
+
			    reponame);
+
		else
+
			printf("Updating repository catalogue\n");
+
	}

	if (pkg_repos_total_count() == 0) {
		fprintf(stderr, "No valid repository found.\n");
@@ -62,8 +69,14 @@ pkgcli_update(bool force) {
	}

	while (pkg_repos(&r) == EPKG_OK) {
-
		if (!pkg_repo_enabled(r))
-
			continue;
+
		if (reponame != NULL) {
+
			if (strcmp(pkg_repo_ident(r), reponame) != 0)
+
				continue;
+
		} else {
+
			if (!pkg_repo_enabled(r))
+
				continue;
+
		}
+

		retcode = pkg_update(r, force);
		if (retcode == EPKG_UPTODATE) {
			if (!quiet)
@@ -87,7 +100,7 @@ pkgcli_update(bool force) {
void
usage_update(void)
{
-
	fprintf(stderr, "Usage: pkg update [-fq]\n\n");
+
	fprintf(stderr, "Usage: pkg update [-fq] [-r reponame]\n\n");
	fprintf(stderr, "For more information see 'pkg help update'.\n");
}

@@ -97,8 +110,9 @@ exec_update(int argc, char **argv)
	int ret;
	int ch;
	bool force = false;
+
	const char *reponame = NULL;

-
	while ((ch = getopt(argc, argv, "fq")) != -1) {
+
	while ((ch = getopt(argc, argv, "fqr:")) != -1) {
		switch (ch) {
		case 'q':
			quiet = true;
@@ -106,6 +120,9 @@ exec_update(int argc, char **argv)
		case 'f':
			force = true;
			break;
+
		case 'r':
+
			reponame = optarg;
+
			break;
		default:
			usage_update();
			return (EX_USAGE);
@@ -128,7 +145,7 @@ exec_update(int argc, char **argv)
	} else if (ret != EPKG_OK)
		return (EX_IOERR);

-
	ret = pkgcli_update(force);
+
	ret = pkgcli_update(force, reponame);

	return ((ret == EPKG_OK) ? EX_OK : EX_SOFTWARE);
}
modified src/upgrade.c
@@ -129,10 +129,10 @@ exec_upgrade(int argc, char **argv)
	
	/* first update the remote repositories if needed */
	if (auto_update &&
-
	    (updcode = pkgcli_update(false)) != EPKG_OK)
+
	    (updcode = pkgcli_update(false, reponame)) != EPKG_OK)
		return (updcode);

-
	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK)
+
	if (pkgdb_open_all(&db, PKGDB_REMOTE, reponame) != EPKG_OK)
		return (EX_IOERR);

	if (pkgdb_obtain_lock(db, lock_type, 0, 0) != EPKG_OK) {
modified src/version.c
@@ -427,12 +427,12 @@ do_source_remote(unsigned int opt, char limchar, char *pattern, match_t match,
	   user is forced to have a repo.sqlite */

	if (auto_update) {
-
		retcode = pkgcli_update(false);
+
		retcode = pkgcli_update(false, reponame);
		if (retcode != EPKG_OK)
			return (retcode);
	}

-
	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK)
+
	if (pkgdb_open_all(&db, PKGDB_REMOTE, reponame) != EPKG_OK)
		return (EX_IOERR);

	if (pkgdb_obtain_lock(db, PKGDB_LOCK_READONLY, 0, 0) != EPKG_OK) {