Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix multirepo upgrade.
Vsevolod Stakhov committed 11 years ago
commit 7db8f506f27b2cbff886eb20c45980f693872ef3
parent 484b5ab
3 files changed +40 -10
modified libpkg/pkg_jobs.c
@@ -1188,30 +1188,40 @@ pkg_jobs_new_candidate(struct pkg *pkg)
static bool
pkg_jobs_check_remote_candidate(struct pkg_jobs *j, struct pkg *pkg)
{
-
	const char *digest;
-
	char sqlbuf[256];
+
	const char *digest, *uid;
	struct pkgdb_it *it;
	struct pkg *p = NULL;

-
	pkg_get(pkg, PKG_DIGEST, &digest);
+
	pkg_get(pkg, PKG_DIGEST, &digest, PKG_UNIQUEID, &uid);
	/* If we have no digest, we need to check this package */
	if (digest == NULL || digest[0] == '\0')
		return (true);

-
	sqlite3_snprintf(sizeof(sqlbuf), sqlbuf, " WHERE manifestdigest=%Q", digest);
-

-
	it = pkgdb_repo_query(j->db, sqlbuf, MATCH_CONDITION, j->reponame);
+
	it = pkgdb_repo_query(j->db, uid, MATCH_EXACT, j->reponame);
	if (it != NULL) {
		/*
		 * If we have the same package in a remote repo, it is not an
		 * installation candidate
		 */
-
		if (pkgdb_it_next(it, &p, PKG_LOAD_BASIC) == EPKG_OK) {
-
			pkg_free(p);
-
			pkgdb_it_free(it);
-
			return (false);
+
		int npkg = 0;
+

+
		while (pkgdb_it_next(it, &p, PKG_LOAD_BASIC) == EPKG_OK) {
+
			const char *rdigest;
+

+
			pkg_get(p, PKG_DIGEST, &rdigest);
+
			/*
+
			 * Check package with the same uid and explore whether digest
+
			 * has been changed
+
			 */
+
			if (strcmp(rdigest, digest) != 0)
+
				npkg ++;
		}
+

+
		pkg_free(p);
		pkgdb_it_free(it);
+

+
		if (npkg == 0)
+
			return (false);
	}

	return (true);
modified libpkg/pkgdb.c
@@ -3225,3 +3225,17 @@ pkgdb_is_dir_used(struct pkgdb *db, const char *dir, int64_t *res)

	return (EPKG_OK);
}
+

+
int
+
pkgdb_repo_count(struct pkgdb *db)
+
{
+
	struct _pkg_repo_list_item *cur;
+
	int result = 0;
+

+
	if (db != NULL) {
+
		LL_FOREACH(db->repos, cur)
+
			result ++;
+
	}
+

+
	return (result);
+
}
modified libpkg/private/pkgdb.h
@@ -162,6 +162,12 @@ int pkgdb_end_solver(struct pkgdb *db);
 */
int pkgdb_check_access(unsigned mode, const char* dbdir, const char *dbname);

+
/**
+
 * Returns number of attached repositories
+
 * @param db
+
 * @return
+
 */
+
int pkgdb_repo_count(struct pkgdb *db);
/*
 * SQLite utility functions
 */