Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge branch 'master' into repo-with-older-versions
Matthew Seaman committed 13 years ago
commit 602b49d386eef7a3b7f9c7a9987576c2502c2b8d
parent 9346ab6
11 files changed +116 -54
modified libpkg/pkg.h
@@ -651,11 +651,12 @@ int pkg_is_installed(struct pkgdb *db, const char *origin);
/**
 * Create a repository database.
 * @param path The path where the repository live.
+
 * @param force If true, rebuild the repository catalogue from scratch
 * @param callback A function which is called at every step of the process.
 * @param data A pointer which is passed to the callback.
 * @param sum An 65 long char array to receive the sha256 sum
 */
-
int pkg_create_repo(char *path, void (*callback)(struct pkg *, void *), void *);
+
int pkg_create_repo(char *path, bool force, void (*callback)(struct pkg *, void *), void *);
int pkg_finish_repo(char *path, pem_password_cb *cb, char *rsa_key_path);

/**
@@ -827,8 +828,9 @@ int pkg_create_staged(const char *, pkg_formats, const char *, const char *, cha

/**
 * Download the latest repo db file and checks its signature if any
+
 * @param force Always download the repo catalogue
 */
-
int pkg_update(const char *name, const char *packagesite);
+
int pkg_update(const char *name, const char *packagesite, bool force);

/**
 * Get statistics information from the package database(s)
modified libpkg/pkg_repo.c
@@ -284,7 +284,7 @@ get_repo_user_version(sqlite3 *sqlite, const char *database, int *reposcver)
}

static int
-
initialize_repo(const char *repodb, sqlite3 **sqlite)
+
initialize_repo(const char *repodb, bool force, sqlite3 **sqlite)
{
	bool incremental = false;
	bool db_not_open;
@@ -375,16 +375,18 @@ initialize_repo(const char *repodb, sqlite3 **sqlite)

		db_not_open = false;

-
		/* If the schema is too old, then we cannot do an incremental
-
		   update.  Delete the existing repo, and promote this to a
+
		/* If the schema is too old, or we're forcing a full
+
		   update, then we cannot do an incremental update.
+
		   Delete the existing repo, and promote this to a
		   full update */
		if (incremental) {
			if (get_repo_user_version(*sqlite, "main", &reposcver) != EPKG_OK)
				return (EPKG_FATAL);
-
			if (reposcver != REPO_SCHEMA_VERSION) {
-
				pkg_emit_error("updating repo schema version "
-
					"from %d to %d", reposcver,
-
					REPO_SCHEMA_VERSION);
+
			if (force || reposcver != REPO_SCHEMA_VERSION) {
+
				if (reposcver != REPO_SCHEMA_VERSION)
+
					pkg_emit_error("updating repo schema version "
+
					     "from %d to %d", reposcver,
+
					     REPO_SCHEMA_VERSION);
				sqlite3_close(*sqlite);
				unlink(repodb);
				incremental = false;
@@ -526,7 +528,7 @@ maybe_delete_conflicting(const char *origin, const char *version,
}

int
-
pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *data)
+
pkg_create_repo(char *path, bool force, void (progress)(struct pkg *pkg, void *data), void *data)
{
	FTS *fts = NULL;
	FTSENT *ent = NULL;
@@ -593,7 +595,7 @@ pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *
			archive_read_finish(a);
	}

-
	if ((retcode = initialize_repo(repodb, &sqlite)) != EPKG_OK)
+
	if ((retcode = initialize_repo(repodb, force, &sqlite)) != EPKG_OK)
		goto cleanup;

	if ((retcode = initialize_prepared_statements(sqlite)) != EPKG_OK)
modified libpkg/update.c
@@ -64,7 +64,7 @@ remote_add_indexes(const char *reponame)
}

int
-
pkg_update(const char *name, const char *packagesite)
+
pkg_update(const char *name, const char *packagesite, bool force)
{
	char url[MAXPATHLEN];
	struct archive *a = NULL;
@@ -94,12 +94,17 @@ pkg_update(const char *name, const char *packagesite)
	}

	snprintf(repofile, sizeof(repofile), "%s/%s.sqlite", dbdir, name);
-
	if (stat(repofile, &st) != -1) {
-
		t = st.st_mtime;
-
		/* add 10 minutes to the timestap because repo.sqlite is
-
		 * always newer than repo.txz, 10 minutes should be enough
-
		 */
-
		t += 600;
+
	if (force)
+
		t = 0;		/* Always fetch */
+
	else {
+
		if (stat(repofile, &st) != -1) {
+
			t = st.st_mtime;
+
			/* add 10 minutes to the timestap because
+
			 * repo.sqlite is always newer than repo.txz,
+
			 * 10 minutes should be enough
+
			 */
+
			t += 600;
+
		}
	}

	if ((rc = pkg_fetch_file(url, tmp, t)) != EPKG_OK) {
modified pkg/fetch.c
@@ -110,7 +110,7 @@ exec_fetch(int argc, char **argv)
	}

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

	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {
modified pkg/install.c
@@ -109,7 +109,7 @@ exec_install(int argc, char **argv)
	}

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

	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {
modified pkg/pkg-repo.8
@@ -20,36 +20,55 @@
.Os
.Sh NAME
.Nm "pkg repo"
-
.Nd creates a package database repository
+
.Nd creates a package repository catalogue
.Sh SYNOPSIS
.Nm
+
.Op Fl fq
.Ao Ar repo-path Ac Op Ar rsa-key
.Sh DESCRIPTION
.Nm
-
is used for creating package repositories of already
-
available packages.
+
is used for creating a catalogue of the available
+
packages in a repository.
.Nm
-
is useful for creating a package repository database,
-
and then sharing it with other people.
+
catalogues are necessary for sharing your package repository with
+
other people.
.Pp
When
.Nm
-
is invoked it will create a package database file (repo.sqlite)
-
which then can be used for remote package installations
-
from
+
is invoked it creates a package repository catalogue (repo.sqlite),
+
with an optional cryptographic signature, as a compressed tarball
+
(repo.txz).
+
Repository users download and cache this on their local machines,
+
for fast lookup of available packages by programs such as
.Xr pkg-install 8 .
.Pp
-
When you want to create a package database repository you need to
-
specify at least the directory which contains packages in
+
To create a package repository catalogue you must specify the
+
top-level directory where all the packages are stored as
.Ar repo-path .
+
.Nm 
+
will search the filesystem beneath
+
.Ar repo-path
+
to find all the packages it contains.
+
Symbolic links are ignored, and only the most recent package for each
+
origin is included in the catalogue.
+
If a catalogue already exists, it will be updated incrementally with
+
any changes to the package collection.
+
This is a significant time savings for large package repositories.
.Pp
-
To sign the repository, specify the path to an RSA private key for the
+
Optionally you may sign the repository catalogue by specifying the
+
path to an RSA private key as the
.Ar rsa-key
argument.
+
Signing the catalogue is strongly recommended.
.Sh OPTIONS
The following options are supported by
.Nm :
.Bl -tag -width F1
+
.It Fl q
+
Force quiet output
+
.It Fl f
+
Force a full rebuild of the package catalogue, discarding any previous
+
content
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
modified pkg/pkg-update.8
@@ -20,26 +20,30 @@
.Os
.Sh NAME
.Nm "pkg update"
-
.Nd updates remote package repository databases
+
.Nd updates the local copy of a repository catalogue from the remote package
+
repository
.Sh SYNOPSIS
.Nm
-
.Op Fl q
+
.Op Fl fq
.Sh DESCRIPTION
.Nm
-
is used for updating from remote package repository databases.
+
is used for updating the local copy of a repository catalogue from the remote
+
package repository database.  Updates to catalogues are normally downloaded
+
only when the master copy on the remote package repository is newer than the
+
local copy.
.Pp
-
The remote repository databases to be updated are defined in the
+
The remote repository catalogues to be updated are defined in the
.Xr pkg.conf 5
file.
.Pp
It is always a good idea to update your remote package
-
repositories before doing a remote install via
+
repository catalogues before doing a remote install via
.Xr pkg-install 8
or upgrades via
.Xr pkg-upgrade 8 .
.Pp
.Ss Signed repositories
-
If the repository is signed and
+
If the repository catalogue is signed and
.Ev PUBKEY
is defined, it will be verified after being downloaded.
See
@@ -51,6 +55,9 @@ The following options are supported by
.Bl -tag -width F1
.It Fl q
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
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
modified pkg/pkgcli.h
@@ -106,7 +106,7 @@ void usage_stats(void);
/* pkg update */
int exec_update(int, char **);
void usage_update(void);
-
int pkgcli_update(void);
+
int pkgcli_update(bool);

/* pkg updating */
int exec_updating(int, char **);
modified pkg/repo.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <readpassphrase.h>
+
#include <unistd.h>

#include <pkg.h>

@@ -36,7 +37,7 @@
void
usage_repo(void)
{
-
	fprintf(stderr, "usage: pkg repo <repo-path> <rsa-key>\n\n");
+
	fprintf(stderr, "usage: pkg repo [-fq] <repo-path> <rsa-key>\n\n");
	fprintf(stderr, "For more information see 'pkg help repo'.\n");
}

@@ -86,25 +87,47 @@ exec_repo(int argc, char **argv)
{
	int retcode = EPKG_OK;
	int pos = 0;
+
	int ch;
	char *rsa_key;
-

-
	if (argc < 2 || argc > 3) {
+
	bool force = false;
+

+
        while ((ch = getopt(argc, argv, "fq")) != -1) {
+
                switch (ch) {
+
		case 'q':
+
			quiet = true;
+
			break;
+
		case 'f':
+
			force = true;
+
			break;
+
		default:
+
			usage_repo();
+
			return (EX_USAGE);
+
                }
+
        }
+
        argc -= optind;
+
        argv += optind;
+

+
	if (argc < 1 || argc > 2) {
		usage_repo();
		return (EX_USAGE);
	}

-
	printf("Generating repo.sqlite in %s:  ", argv[1]);
-
	retcode = pkg_create_repo(argv[1], progress, &pos);
+
	if (!quiet) {
+
		printf("Generating repo.sqlite in %s:  ", argv[0]);
+
		retcode = pkg_create_repo(argv[0], force, progress, &pos);
+
	} else
+
		retcode = pkg_create_repo(argv[0], force, NULL, NULL);

	if (retcode != EPKG_OK) {
-
		printf("cannot create repository\n");
+
		printf("cannot create repository catalogue\n");
		return (retcode);
	} else {
-
		printf("\bdone!\n");
+
		if (!quiet)
+
			printf("\bdone!\n");
	}
	
-
	rsa_key = (argc == 3) ? argv[2] : NULL;
-
	pkg_finish_repo(argv[1], password_cb, rsa_key);
+
	rsa_key = (argc == 2) ? argv[1] : NULL;
+
	pkg_finish_repo(argv[0], password_cb, rsa_key);

	return (retcode);
}
modified pkg/update.c
@@ -44,7 +44,7 @@
 * Fetch remote databases.
 */
int
-
pkgcli_update(void) {
+
pkgcli_update(bool force) {
	const char *packagesite = NULL;
	const char *repo_name;
	bool multi_repos = false;
@@ -69,7 +69,7 @@ pkgcli_update(void) {
			return (1);
		}

-
		retcode = pkg_update("repo", packagesite);
+
		retcode = pkg_update("repo", packagesite, force);
		if (retcode == EPKG_UPTODATE) {
			if (!quiet)
				printf("Remote repository up-to-date, no need to upgrade\n");
@@ -81,7 +81,7 @@ pkgcli_update(void) {
			repo_name = pkg_config_kv_get(repokv, PKG_CONFIG_KV_KEY);
			packagesite = pkg_config_kv_get(repokv, PKG_CONFIG_KV_VALUE);

-
			retcode = pkg_update(repo_name, packagesite);
+
			retcode = pkg_update(repo_name, packagesite, force);
			if (retcode == EPKG_UPTODATE) {
				if (!quiet)
					printf("%s repository up-to-date, no need to upgrade\n", repo_name);
@@ -97,7 +97,7 @@ pkgcli_update(void) {
void
usage_update(void)
{
-
	fprintf(stderr, "usage: pkg update [-q]\n\n");
+
	fprintf(stderr, "usage: pkg update [-fq]\n\n");
	fprintf(stderr, "For more information see 'pkg help update'.\n");
}

@@ -106,12 +106,16 @@ exec_update(int argc, char **argv)
{
	int retcode = EPKG_OK;
	int ch;
+
	bool force = false;

-
	while ((ch = getopt(argc, argv, "q")) != -1) {
+
	while ((ch = getopt(argc, argv, "fq")) != -1) {
		switch (ch) {
			case 'q':
				quiet = true;
				break;
+
			case 'f':
+
				force = true;
+
				break;
			default:
				usage_update();
				return (EX_USAGE);
@@ -130,7 +134,7 @@ exec_update(int argc, char **argv)
		return (EX_NOPERM);
	}

-
	retcode = pkgcli_update();
+
	retcode = pkgcli_update(force);

	return (retcode);
}
modified pkg/upgrade.c
@@ -92,7 +92,7 @@ exec_upgrade(int argc, char **argv)
	}

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

	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {