Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Rework provides/requires.
Vsevolod Stakhov committed 11 years ago
commit d05a224fad1b4b5f08386c8839890357c7930773
parent 3a5165a
1 file changed +116 -164
modified libpkg/pkg_jobs_universe.c
@@ -340,111 +340,122 @@ pkg_jobs_universe_process_conflicts(struct pkg_jobs_universe *universe,
}

static int
-
pkg_jobs_universe_process_shlibs(struct pkg_jobs_universe *universe,
-
	struct pkg *pkg)
+
pkg_jobs_universe_handle_provide(struct pkg_jobs_universe *universe,
+
		struct pkgdb_it *it, const char *name, bool is_shlib)
{
-
	struct pkg_shlib *shlib = NULL;
	struct pkg_job_universe_item *unit;
	struct pkg_job_provide *pr, *prhead;
-
	struct pkgdb_it *it;
	struct pkg *npkg, *rpkg;
	unsigned flags = PKG_LOAD_BASIC|PKG_LOAD_OPTIONS|PKG_LOAD_DEPS|
				PKG_LOAD_REQUIRES|PKG_LOAD_PROVIDES|
				PKG_LOAD_SHLIBS_REQUIRED|PKG_LOAD_SHLIBS_PROVIDED|
				PKG_LOAD_ANNOTATIONS|PKG_LOAD_CONFLICTS;

-
	while (pkg_shlibs_required(pkg, &shlib) == EPKG_OK) {
-
		HASH_FIND_STR(universe->provides, shlib->name, pr);
-
		if (pr != NULL)
-
			continue;
+
	rpkg = NULL;
+
	prhead = NULL;
+
	while (pkgdb_it_next(it, &rpkg, flags) == EPKG_OK) {
+
		/* Check for local packages */
+
		HASH_FIND_STR(universe->items, rpkg->uid, unit);
+
		if (unit != NULL) {
+
			if (pkg_jobs_need_upgrade (rpkg, unit->pkg)) {
+
				/* Remote provide is newer, so we can add it */
+
				if (pkg_jobs_universe_process_item(universe, rpkg,
+
						&unit) != EPKG_OK)
+
					continue;

-
		/* Not found, search in the repos */
-
		it = pkgdb_repo_shlib_provide(universe->j->db,
-
			shlib->name, universe->j->reponame);
-
		if (it != NULL) {
-
			rpkg = NULL;
-
			prhead = NULL;
-
			while (pkgdb_it_next(it, &rpkg, flags) == EPKG_OK) {
-
				/* Check for local packages */
-
				HASH_FIND_STR(universe->items, rpkg->uid, unit);
-
				if (unit != NULL) {
-
					if (pkg_jobs_need_upgrade (rpkg, unit->pkg)) {
-
						/* Remote provide is newer, so we can add it */
-
						if (pkg_jobs_universe_process_item(universe, rpkg,
+
				rpkg = NULL;
+
			}
+
		}
+
		else {
+
			/* Maybe local package has just been not added */
+
			npkg = pkg_jobs_universe_get_local(universe, rpkg->uid, 0);
+
			if (npkg != NULL) {
+
				if (pkg_jobs_universe_process_item(universe, npkg,
+
						&unit) != EPKG_OK) {
+
					return (EPKG_FATAL);
+
				}
+
				if (pkg_jobs_need_upgrade (rpkg, npkg)) {
+
					/* Remote provide is newer, so we can add it */
+
					if (pkg_jobs_universe_process_item(universe, rpkg,
							&unit) != EPKG_OK)
-
							continue;
-

-
						rpkg = NULL;
-
					}
+
						continue;
				}
-
				else {
-
					/* Maybe local package has just been not added */
-
					npkg = pkg_jobs_universe_get_local(universe, rpkg->uid, 0);
-
					if (npkg != NULL) {
-
						if (pkg_jobs_universe_process_item(universe, npkg,
-
							&unit) != EPKG_OK) {
-
							return (EPKG_FATAL);
-
						}
-
						if (pkg_jobs_need_upgrade (rpkg, npkg)) {
-
							/* Remote provide is newer, so we can add it */
-
							if (pkg_jobs_universe_process_item(universe, rpkg,
-
								&unit) != EPKG_OK)
-
								continue;
-
						}
-
					}
+
			}
+
		}
+

+
		/* Skip seen packages */
+
		if (unit == NULL) {
+
			struct pkg_job_seen *seen;
+

+
			if (rpkg->digest == NULL) {
+
				pkg_debug(3, "no digest found for package %s", rpkg->uid);
+
				if (pkg_checksum_calculate(rpkg, universe->j->db) != EPKG_OK) {
+
					return (EPKG_FATAL);
				}
+
			}
+
			HASH_FIND_STR(universe->seen, rpkg->digest, seen);
+
			if (seen == NULL) {
+
				pkg_jobs_universe_process_item(universe, rpkg,
+
						&unit);

-
				/* Skip seen packages */
-
				if (unit == NULL) {
-
					struct pkg_job_seen *seen;
+
				/* Reset package to avoid freeing */
+
				rpkg = NULL;
+
			}
+
			else {
+
				unit = seen->un;
+
			}
+
		}

-
					if (rpkg->digest == NULL) {
-
						pkg_debug(3, "no digest found for package %s", rpkg->uid);
-
						if (pkg_checksum_calculate(pkg, universe->j->db) != EPKG_OK) {
-
							return (EPKG_FATAL);
-
						}
-
					}
-
					HASH_FIND_STR(universe->seen, rpkg->digest, seen);
-
					if (seen == NULL) {
-
						pkg_jobs_universe_process_item(universe, rpkg,
-
							&unit);
+
		pr = calloc (1, sizeof (*pr));
+
		if (pr == NULL) {
+
			pkg_emit_errno("pkg_jobs_add_universe", "calloc: "
+
					"struct pkg_job_provide");
+
			return (EPKG_FATAL);
+
		}

-
						/* Reset package to avoid freeing */
-
						rpkg = NULL;
-
					}
-
					else {
-
						unit = seen->un;
-
					}
-
				}
+
		pr->un = unit;
+
		pr->provide = name;
+
		pr->is_shlib = is_shlib;

-
				pr = calloc (1, sizeof (*pr));
-
				if (pr == NULL) {
-
					pkg_emit_errno("pkg_jobs_add_universe", "calloc: "
-
						"struct pkg_job_provide");
-
					return (EPKG_FATAL);
-
				}
+
		if (prhead == NULL) {
+
			DL_APPEND(prhead, pr);
+
			HASH_ADD_KEYPTR(hh, universe->provides, pr->provide,
+
					strlen(pr->provide), prhead);
+
		}
+
		else {
+
			DL_APPEND(prhead, pr);
+
		}
+
	}

-
				pr->un = unit;
-
				pr->provide = shlib->name;
-
				pr->is_shlib = true;
+
	return (EPKG_OK);
+
}

-
				if (prhead == NULL) {
-
					DL_APPEND(prhead, pr);
-
					HASH_ADD_KEYPTR(hh, universe->provides, pr->provide,
-
						strlen(pr->provide), prhead);
-
				}
-
				else {
-
					DL_APPEND(prhead, pr);
-
				}
-
			}
+
static int
+
pkg_jobs_universe_process_shlibs(struct pkg_jobs_universe *universe,
+
	struct pkg *pkg)
+
{
+
	struct pkg_shlib *shlib = NULL;
+
	struct pkg_job_provide *pr;
+
	struct pkgdb_it *it;
+
	int rc;
+

+
	while (pkg_shlibs_required(pkg, &shlib) == EPKG_OK) {
+
		HASH_FIND_STR(universe->provides, shlib->name, pr);
+
		if (pr != NULL)
+
			continue;
+

+
		/* Not found, search in the repos */
+
		it = pkgdb_repo_shlib_provide(universe->j->db,
+
			shlib->name, universe->j->reponame);
+

+
		if (it != NULL) {
+
			rc = pkg_jobs_universe_handle_provide(universe, it, shlib->name, true);
			pkgdb_it_free(it);
-
			if (prhead == NULL) {
-
				pkg_debug(1, "cannot find packages that provide %s required for %s",
+

+
			if (rc != EPKG_OK) {
+
				pkg_debug(1, "cannot find packages that provide library %s "
+
						"required for %s",
				    shlib->name, pkg->name);
-
				/*
-
				 * XXX: this is not normal but it is very common for the existing
-
				 * repos, hence we just ignore this stale dependency
-
				 */
			}
		}
	}
@@ -461,6 +472,7 @@ pkg_jobs_universe_process_provides_requires(struct pkg_jobs_universe *universe,
	struct pkg_job_provide *pr, *prhead;
	struct pkgdb_it *it;
	struct pkg *npkg, *rpkg;
+
	int rc;
	unsigned flags = PKG_LOAD_BASIC|PKG_LOAD_OPTIONS|PKG_LOAD_DEPS|
				PKG_LOAD_REQUIRES|PKG_LOAD_PROVIDES|
				PKG_LOAD_SHLIBS_REQUIRED|PKG_LOAD_SHLIBS_PROVIDED|
@@ -472,92 +484,32 @@ pkg_jobs_universe_process_provides_requires(struct pkg_jobs_universe *universe,
		if (pr != NULL)
			continue;

-
		/* Not found, search in the repos */
-
		it = pkgdb_repo_provide(universe->j->db,
-
			p->provide, universe->j->reponame);
+
		/* Check for local provides */
+
		it = pkgdb_query_provide(universe->j->db, p->provide);
		if (it != NULL) {
-
			rpkg = NULL;
-
			prhead = NULL;
-
			while (pkgdb_it_next(it, &rpkg, flags) == EPKG_OK) {
-
				/* Check for local packages */
-
				HASH_FIND_STR(universe->items, rpkg->uid, unit);
-
				if (unit != NULL) {
-
					if (pkg_jobs_need_upgrade (rpkg, unit->pkg)) {
-
						/* Remote provide is newer, so we can add it */
-
						if (pkg_jobs_universe_process_item(universe, rpkg,
-
							&unit) != EPKG_OK)
-
							continue;
-

-
						rpkg = NULL;
-
					}
-
				}
-
				else {
-
					/* Maybe local package has just been not added */
-
					npkg = pkg_jobs_universe_get_local(universe, rpkg->uid, 0);
-
					if (npkg != NULL) {
-
						if (pkg_jobs_universe_process_item(universe, npkg,
-
							&unit) != EPKG_OK)
-
							return (EPKG_FATAL);
-
						if (pkg_jobs_need_upgrade (rpkg, npkg)) {
-
							/* Remote provide is newer, so we can add it */
-
							if (pkg_jobs_universe_process_item(universe, rpkg,
-
								&unit) != EPKG_OK)
-
								continue;
-
						}
-
					}
-
				}
-

-
				/* Skip seen packages */
-
				if (unit == NULL) {
-
					struct pkg_job_seen *seen;
-

-
					if (rpkg->digest == NULL) {
-
						pkg_debug(3, "no digest found for package %s", rpkg->uid);
-
						if (pkg_checksum_calculate(pkg, universe->j->db) != EPKG_OK) {
-
							return (EPKG_FATAL);
-
						}
-
					}
-
					HASH_FIND_STR(universe->seen, rpkg->digest, seen);
-
					if (seen == NULL) {
-
						pkg_jobs_universe_process_item(universe, rpkg,
-
							&unit);
-

-
						/* Reset package to avoid freeing */
-
						rpkg = NULL;
-
					}
-
					else {
-
						unit = seen->un;
-
					}
-
				}
+
			rc = pkg_jobs_universe_handle_provide(universe, it, p->provide, false);
+
			pkgdb_it_free(it);

-
				pr = calloc (1, sizeof (*pr));
-
				if (pr == NULL) {
-
					pkg_emit_errno("pkg_jobs_add_universe", "calloc: "
-
						"struct pkg_job_provide");
-
					return (EPKG_FATAL);
-
				}
+
			if (rc != EPKG_OK) {
+
				pkg_debug(1, "cannot find local packages that provide %s "
+
						"required for %s",
+
						p->provide, pkg->name);
+
			}
+
		}

-
				pr->un = unit;
-
				pr->provide = p->provide;
-
				pr->is_shlib = false;
+
		/* Not found, search in the repos */
+
		it = pkgdb_repo_provide(universe->j->db,
+
			p->provide, universe->j->reponame);

-
				if (prhead == NULL) {
-
					DL_APPEND(prhead, pr);
-
					HASH_ADD_KEYPTR(hh, universe->provides, pr->provide,
-
						strlen(pr->provide), prhead);
-
				}
-
				else {
-
					DL_APPEND(prhead, pr);
-
				}
-
			}
+
		if (it != NULL) {
+
			rc = pkg_jobs_universe_handle_provide(universe, it, p->provide, false);
			pkgdb_it_free(it);
-
			if (prhead == NULL) {
-
				pkg_debug(1, "cannot find packages that provide %s required for %s",
+

+
			if (rc != EPKG_OK) {
+
				pkg_debug(1, "cannot find remote packages that provide %s "
+
						"required for %s",
				    p->provide, pkg->name);
-
				/*
-
				 * XXX: this is not normal but it is very common for the existing
-
				 * repos, hence we just ignore this stale dependency
-
				 */
+
				return (rc);
			}
		}
	}