Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add olddigest field.
Vsevolod Stakhov committed 11 years ago
commit 4ebbd9e11c145751397e651741863c43f5d973cd
parent c81ecfb
6 files changed +34 -15
modified libpkg/pkg.h.in
@@ -254,6 +254,7 @@ typedef enum {
	PKG_LICENSES,
	PKG_CATEGORIES,
	PKG_UNIQUEID,
+
	PKG_OLD_DIGEST,
	PKG_NUM_FIELDS, 	/* end of fields */
} pkg_attr;

modified libpkg/pkg_repo_update.c
@@ -86,7 +86,7 @@ pkg_repo_register(struct pkg_repo *repo, sqlite3 *sqlite)

static int
pkg_repo_add_from_manifest(char *buf, const char *origin, long offset,
-
		const char *manifest_digest, sqlite3 *sqlite,
+
		sqlite3 *sqlite,
		struct pkg_manifest_key **keys, struct pkg **p)
{
	int rc = EPKG_OK;
@@ -127,7 +127,7 @@ pkg_repo_add_from_manifest(char *buf, const char *origin, long offset,
		goto cleanup;
	}

-
	rc = pkgdb_repo_add_package(pkg, NULL, sqlite, manifest_digest, true);
+
	rc = pkgdb_repo_add_package(pkg, NULL, sqlite, true);

cleanup:
	return (rc);
@@ -244,6 +244,10 @@ pkg_repo_update_incremental(const char *name, struct pkg_repo *repo, time_t *mti

	while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) == EPKG_OK) {
		pkg_get(pkg, PKG_ORIGIN, &origin, PKG_DIGEST, &digest);
+
		if (digest == NULL) {
+
			pkg_checksum_calculate(pkg, NULL);
+
			pkg_get(pkg, PKG_DIGEST, &digest);
+
		}
		pkg_repo_update_increment_item_new(&ldel, origin, digest, 4, 0);
	}

@@ -399,12 +403,11 @@ pkg_repo_update_incremental(const char *name, struct pkg_repo *repo, time_t *mti
		if (rc == EPKG_OK) {
			if (item->length != 0) {
				rc = pkg_repo_add_from_manifest(map + item->offset, item->origin,
-
						item->length, item->digest,
-
						sqlite, &keys, &pkg);
+
						item->length, sqlite, &keys, &pkg);
			}
			else {
				rc = pkg_repo_add_from_manifest(map + item->offset, item->origin,
-
						len - item->offset, item->digest, sqlite, &keys, &pkg);
+
						len - item->offset, sqlite, &keys, &pkg);
			}
		}
		free(item->origin);
modified libpkg/pkgdb_repo.c
@@ -59,7 +59,7 @@
/* The package repo schema minor revision.
   Minor schema changes don't prevent older pkgng
   versions accessing the repo. */
-
#define REPO_SCHEMA_MINOR 9
+
#define REPO_SCHEMA_MINOR 10

/* REPO_SCHEMA_VERSION=2007 */
#define REPO_SCHEMA_VERSION (REPO_SCHEMA_MAJOR * 1000 + REPO_SCHEMA_MINOR)
@@ -90,10 +90,10 @@ static sql_prstmt sql_prepared_statements[PRSTMT_LAST] = {
		NULL,
		"INSERT INTO packages ("
		"origin, name, version, comment, desc, arch, maintainer, www, "
-
		"prefix, pkgsize, flatsize, licenselogic, cksum, path, manifestdigest"
+
		"prefix, pkgsize, flatsize, licenselogic, cksum, path, manifestdigest, olddigest"
		")"
-
		"VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15)",
-
		"TTTTTTTTTIIITTT",
+
		"VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16)",
+
		"TTTTTTTTTIIITTTT",
	},
	[DEPS] = {
		NULL,
@@ -468,10 +468,11 @@ pkgdb_repo_cksum_exists(sqlite3 *sqlite, const char *cksum)

int
pkgdb_repo_add_package(struct pkg *pkg, const char *pkg_path,
-
		sqlite3 *sqlite, const char *manifest_digest, bool forced)
+
		sqlite3 *sqlite, bool forced)
{
	const char *name, *version, *origin, *comment, *desc;
	const char *arch, *maintainer, *www, *prefix, *sum, *rpath;
+
	const char *olddigest, *manifestdigest;
	int64_t			 flatsize, pkgsize;
	int64_t			 licenselogic;
	int			 ret;
@@ -490,13 +491,14 @@ pkgdb_repo_add_package(struct pkg *pkg, const char *pkg_path,
			    PKG_LICENSE_LOGIC, &licenselogic, PKG_CKSUM, &sum,
			    PKG_PKGSIZE, &pkgsize, PKG_REPOPATH, &rpath,
			    PKG_LICENSES, &licenses, PKG_CATEGORIES, &categories,
-
			    PKG_ANNOTATIONS, &annotations);
+
			    PKG_ANNOTATIONS, &annotations, PKG_OLD_DIGEST, &olddigest,
+
			    PKG_DIGEST, &manifestdigest);

try_again:
	if ((ret = run_prepared_statement(PKG, origin, name, version,
			comment, desc, arch, maintainer, www, prefix,
			pkgsize, flatsize, (int64_t)licenselogic, sum,
-
			rpath, manifest_digest)) != SQLITE_DONE) {
+
			rpath, manifestdigest, olddigest)) != SQLITE_DONE) {
		if (ret == SQLITE_CONSTRAINT) {
			switch(maybe_delete_conflicting(origin,
					version, pkg_path, forced)) {
modified libpkg/private/pkg.h
@@ -399,6 +399,7 @@ static struct pkg_key {
	[PKG_LICENSES] = { "licenses", UCL_ARRAY },
	[PKG_CATEGORIES] = { "catagories", UCL_ARRAY },
	[PKG_UNIQUEID] = { "uniqueid", UCL_STRING },
+
	[PKG_OLD_DIGEST] = { "olddigest", UCL_STRING },
};

int pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url,
modified libpkg/private/pkgdb.h
@@ -109,13 +109,12 @@ int pkgdb_repo_cksum_exists(sqlite3 *sqlite, const char *cksum);
 * @param pkg package structure
 * @param pkg_path path triggered package addition
 * @param sqlite sqlite pointer
-
 * @param manifest_digest sha256 checksum of the manifest of the package
 * @param forced force adding of package even if it is outdated
 * @return EPKG_OK if package added, EPKG_END if package already exists and is newer than
 * inserted one, EPKG_FATAL if error occurred
 */
int pkgdb_repo_add_package(struct pkg *pkg, const char *pkg_path,
-
		sqlite3 *sqlite, const char *manifest_digest, bool forced);
+
		sqlite3 *sqlite, bool forced);

/**
 * Remove specified pkg from repo
modified libpkg/private/repodb.h
@@ -60,7 +60,8 @@ static const char initsql[] = ""
	    /* relative path to the package in the repository */
	    "path TEXT NOT NULL,"
	    "pkg_format_version INTEGER,"
-
	    "manifestdigest TEXT NULL"
+
	    "manifestdigest TEXT NULL,"
+
	    "olddigest TEXT NULL"
	");"
	"CREATE TABLE deps ("
	    "origin TEXT,"
@@ -354,6 +355,12 @@ static const struct repo_changes repo_upgrades[] = {
	 "CREATE INDEX IF NOT EXISTS %Q.packages_version ON packages(name, version);"
	 "CREATE UNIQUE INDEX IF NOT EXISTS %Q.packages_digest ON packages(manifestdigest);"
	},
+
	{2009,
+
	 2010,
+
	 "Add legacy digest field",
+

+
	 "ALTER TABLE %Q.packages ADD COLUMN olddigest TEXT NULL;"
+
	},
	/* Mark the end of the array */
	{ -1, -1, NULL, NULL, }

@@ -362,6 +369,12 @@ static const struct repo_changes repo_upgrades[] = {
/* How to downgrade a newer repo to match what the current system
   expects */
static const struct repo_changes repo_downgrades[] = {
+
	{2010,
+
	 2009,
+
	 "Drop olddigest field",
+

+
	 "ALTER TABLE %Q.packages REMOVE COLUMN olddigest;"
+
	},
	{2009,
	 2008,
	 "Drop indicies",