Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Rework candidates selection.
Vsevolod Stakhov committed 11 years ago
commit b21c0c5d410970b8cf47de3c1635b83170dfe50e
parent 4d49c01
3 files changed +107 -84
modified libpkg/pkg_jobs.c
@@ -383,7 +383,7 @@ pkg_jobs_test_automatic(struct pkg_jobs *j, struct pkg *p)
	bool automatic;

	while (pkg_rdeps(p, &d) == EPKG_OK && ret) {
-
		HASH_FIND_STR(j->universe, d->uid, unit);
+
		unit = pkg_jobs_universe_find(j->universe, d->uid);
		if (unit != NULL) {
			pkg_get(unit->pkg, PKG_AUTOMATIC, &automatic);
			if (!automatic) {
@@ -404,7 +404,7 @@ pkg_jobs_test_automatic(struct pkg_jobs *j, struct pkg *p)
				pkg_free(npkg);
				return (false);
			}
-
			if (pkg_jobs_add_universe(j, npkg, false, false, NULL) != EPKG_OK)
+
			if (pkg_jobs_universe_process_package(j->universe, npkg) != EPKG_OK)
				return (false);
		}

@@ -442,7 +442,7 @@ new_pkg_version(struct pkg_jobs *j)
		goto end;
	}

-
	pkg_jobs_add_universe(j, p, true, false, NULL);
+
	pkg_jobs_universe_process_package(j->universe, p);

	/* Use maximum priority for pkg */
	if (pkg_jobs_find_remote_pkg(j, uid, MATCH_EXACT, false, true, true) == EPKG_OK) {
@@ -477,7 +477,7 @@ pkg_jobs_process_remote_pkg(struct pkg_jobs *j, struct pkg *p,
		}
		pkg_get(p, PKG_DIGEST, &digest);
	}
-
	HASH_FIND_STR(j->seen, digest, seen);
+
	seen = pkg_jobs_universe_seen(j->universe, digest);
	if (seen != NULL) {
		/* We have already added exactly the same package to the universe */
		pkg_debug(3, "already seen package %s-%s(%c) in the universe, do not add it again",
@@ -493,14 +493,14 @@ pkg_jobs_process_remote_pkg(struct pkg_jobs *j, struct pkg *p,
			if (jreq == NULL)
				pkg_jobs_add_req(j, uid, seen->un);
			if (force) {
-
				seen->un->reinstall = p;
+
				pkg_jobs_universe_add_pkg(j->universe, p, true, NULL);
				pkg_get(seen->un->pkg, PKG_AUTOMATIC, &automatic);
				pkg_set(p, PKG_AUTOMATIC, automatic);
			}
		}
		return (EPKG_OK);
	}
-
	HASH_FIND_STR(j->universe, uid, jit);
+
	jit = pkg_jobs_universe_find(j->universe, uid);
	if (jit != NULL) {
		/* We have a more recent package */
		if (!force && !pkg_need_upgrade(p, jit->pkg, false)) {
@@ -536,65 +536,21 @@ pkg_jobs_process_remote_pkg(struct pkg_jobs *j, struct pkg *p,
	rc = EPKG_OK;
	p->direct = root;
	/* Add a package to request chain and populate universe */
-
	rc = pkg_jobs_add_universe(j, p, recursive, false, &jit);
-
	if (add_request)
-
		pkg_jobs_add_req(j, uid, jit);
+
	rc = pkg_jobs_process_universe(j->universe, p, &jit);

-
	if (unit != NULL)
-
		*unit = jit;
+
	if (rc == EPKG_OK) {
+
		if (add_request)
+
			pkg_jobs_add_req(j, uid, jit);

-
	return (rc);
-
}
-

-
static void
-
pkg_jobs_change_uid(struct pkg_jobs *j, struct pkg_job_universe_item *unit,
-
	const char *new_uid, size_t uidlen, bool update_rdeps)
-
{
-
	struct pkg_dep *rd = NULL, *d = NULL;
-
	struct pkg_job_universe_item *found;
-
	struct pkg *lp;
-
	const char *old_uid;
-
	struct pkg_job_replace *replacement;
-

-
	pkg_get(unit->pkg, PKG_UNIQUEID, &old_uid);
-

-
	if (update_rdeps) {
-
		/* For all rdeps update deps accordingly */
-
		while (pkg_rdeps(unit->pkg, &rd) == EPKG_OK) {
-
			HASH_FIND(hh, j->universe, rd->uid, strlen(rd->uid), found);
-
			if (found == NULL) {
-
				lp = pkg_jobs_get_local_pkg(j, rd->uid, 0);
-
				pkg_jobs_add_universe(j, lp, true, false, &found);
-
			}
-

-
			if (found != NULL) {
-
				while (pkg_deps(found->pkg, &d) == EPKG_OK) {
-
					if (strcmp(d->uid, old_uid) == 0) {
-
						free(d->uid);
-
						d->uid = strdup(new_uid);
-
					}
-
				}
-
			}
-
		}
+
		if (unit != NULL)
+
			*unit = jit;
	}

-
	replacement = calloc(1, sizeof(*replacement));
-
	if (replacement != NULL) {
-
		replacement->old_uid = strdup(old_uid);
-
		replacement->new_uid = strdup(new_uid);
-
		LL_PREPEND(j->uid_replaces, replacement);
-
	}
-

-
	HASH_DELETE(hh, j->universe, unit);
-
	pkg_set(unit->pkg, PKG_UNIQUEID, new_uid);
-
	HASH_FIND(hh, j->universe, new_uid, uidlen, found);
-
	if (found != NULL)
-
		DL_APPEND(found, unit);
-
	else
-
		HASH_ADD_KEYPTR(hh, j->universe, new_uid, uidlen, unit);
-

+
	return (rc);
}

+
static
+

static int
pkg_jobs_try_remote_candidate(struct pkg_jobs *j, const char *pattern,
		const char *uid, match_t m)
@@ -622,9 +578,9 @@ pkg_jobs_try_remote_candidate(struct pkg_jobs *j, const char *pattern,
		if (pkg_emit_query_yesno(true, sbuf_data(qmsg))) {
			/* Change the origin of the local package */
			pkg_validate(p);
-
			HASH_FIND(hh, j->universe, uid, strlen(uid), unit);
+
			unit = pkg_jobs_universe_find(j->universe, uid);
			if (unit != NULL)
-
				pkg_jobs_change_uid(j, unit, fuid, strlen(fuid), false);
+
				pkg_jobs_universe_change_uid(j, unit, fuid, strlen(fuid), false);

			rc = pkg_jobs_process_remote_pkg(j, p, true, false, true,
				NULL, true);
@@ -659,8 +615,10 @@ pkg_jobs_guess_upgrade_candidate(struct pkg_jobs *j, const char *pattern)
	/* First of all, try to search a package with the same name */
	pos = strchr(pattern, '/');
	if (pos != NULL && pos[1] != '\0') {
-
		if (pkg_jobs_try_remote_candidate(j, pos + 1, opattern, MATCH_EXACT) == EPKG_OK)
+
		if (pkg_jobs_try_remote_candidate(j, pos + 1, opattern, MATCH_EXACT)
+
						== EPKG_OK)
			return (EPKG_OK);
+

		pos ++;
		pattern = pos;
	}
modified libpkg/pkg_jobs_universe.c
@@ -110,9 +110,9 @@ pkg_universe_get_remote_pkg(struct pkg_jobs_universe *universe,
 * Check whether a package is in the universe already or add it
 * @return item or NULL
 */
-
static int
+
int
pkg_jobs_universe_add_pkg(struct pkg_jobs_universe *universe, struct pkg *pkg,
-
		struct pkg_job_universe_item **found)
+
		bool force, struct pkg_job_universe_item **found)
{
	struct pkg_job_universe_item *item, *tmp = NULL;
	const char *uid, *digest, *version, *name;
@@ -131,7 +131,7 @@ pkg_jobs_universe_add_pkg(struct pkg_jobs_universe *universe, struct pkg *pkg,
	}

	HASH_FIND_STR(universe->seen, digest, seen);
-
	if (seen != NULL) {
+
	if (seen != NULL && !force) {
		if (found != NULL)
			*found = seen->un;

@@ -156,11 +156,17 @@ pkg_jobs_universe_add_pkg(struct pkg_jobs_universe *universe, struct pkg *pkg,

	DL_APPEND(tmp, item);

-
	seen = calloc(1, sizeof(struct pkg_job_seen));
-
	seen->digest = digest;
-
	seen->un = item;
-
	HASH_ADD_KEYPTR(hh, universe->seen, seen->digest, strlen(seen->digest),
-
		seen);
+
	if (seen == NULL) {
+
		seen = calloc(1, sizeof(struct pkg_job_seen));
+
		if (seen == NULL) {
+
			pkg_emit_errno("pkg_jobs_universe_add_pkg", "calloc: struct pkg_job_seen)");
+
			return (EPKG_FATAL);
+
		}
+
		seen->digest = digest;
+
		seen->un = item;
+
		HASH_ADD_KEYPTR(hh, universe->seen, seen->digest, strlen(seen->digest),
+
			seen);
+
	}

	universe->nitems++;

@@ -413,7 +419,7 @@ pkg_jobs_universe_process_shlibs(struct pkg_jobs_universe *universe,
	return (EPKG_OK);
}

-
static int
+
int
pkg_jobs_process_universe(struct pkg_jobs_universe *universe, struct pkg *pkg,
		struct pkg_job_universe_item **result)
{
@@ -424,7 +430,8 @@ pkg_jobs_process_universe(struct pkg_jobs_universe *universe, struct pkg *pkg,
	job_flags = universe->j->flags;

	/* Add pkg itself */
-
	rc = pkg_jobs_universe_add_pkg(universe, pkg, result);
+
	rc = pkg_jobs_universe_add_pkg(universe, pkg, false,
+
		result);
	if (rc == EPKG_END)
		return (EPKG_OK);
	else if (rc != EPKG_OK)
@@ -658,24 +665,14 @@ void
pkg_jobs_universe_free(struct pkg_jobs_universe *universe)
{
	struct pkg_job_universe_item *un, *untmp, *cur, *curtmp;
-
	struct pkg *reinstall = NULL;

	HASH_ITER(hh, universe->items, un, untmp) {
		HASH_DEL(universe->items, un);

-
		if (un->reinstall != NULL)
-
			reinstall = un->reinstall;
-

		LL_FOREACH_SAFE(un, cur, curtmp) {
-
			if (cur->pkg != reinstall)
-
				pkg_free(cur->pkg);
+
			pkg_free(cur->pkg);
			free(cur);
		}
-

-
		if (reinstall != NULL)
-
			pkg_free(reinstall);
-

-
		reinstall = NULL;
	}
	HASH_FREE(universe->seen, free);
	HASH_FREE(universe->provides, pkg_jobs_universe_provide_free);
@@ -718,3 +715,53 @@ pkg_jobs_universe_seen(struct pkg_jobs_universe *universe, const char *digest)

	return (seen != NULL);
}
+

+
void
+
pkg_jobs_universe_change_uid(struct pkg_jobs_universe *universe,
+
	struct pkg_job_universe_item *unit,
+
	const char *new_uid, size_t uidlen, bool update_rdeps)
+
{
+
	struct pkg_dep *rd = NULL, *d = NULL;
+
	struct pkg_job_universe_item *found;
+
	struct pkg *lp;
+
	const char *old_uid;
+
	struct pkg_job_replace *replacement;
+

+
	pkg_get(unit->pkg, PKG_UNIQUEID, &old_uid);
+

+
	if (update_rdeps) {
+
		/* For all rdeps update deps accordingly */
+
		while (pkg_rdeps(unit->pkg, &rd) == EPKG_OK) {
+
			found = pkg_jobs_universe_find(universe, rd->uid);
+
			if (found == NULL) {
+
				lp = pkg_universe_get_local_pkg(universe, rd->uid, 0);
+
				pkg_jobs_process_universe(universe, lp, &found);
+
			}
+

+
			if (found != NULL) {
+
				while (pkg_deps(found->pkg, &d) == EPKG_OK) {
+
					if (strcmp(d->uid, old_uid) == 0) {
+
						free(d->uid);
+
						d->uid = strdup(new_uid);
+
					}
+
				}
+
			}
+
		}
+
	}
+

+
	replacement = calloc(1, sizeof(*replacement));
+
	if (replacement != NULL) {
+
		replacement->old_uid = strdup(old_uid);
+
		replacement->new_uid = strdup(new_uid);
+
		LL_PREPEND(universe->uid_replaces, replacement);
+
	}
+

+
	HASH_DELETE(hh, universe->items, unit);
+
	pkg_set(unit->pkg, PKG_UNIQUEID, new_uid);
+
	HASH_FIND(hh, universe->items, new_uid, uidlen, found);
+
	if (found != NULL)
+
		DL_APPEND(found, unit);
+
	else
+
		HASH_ADD_KEYPTR(hh, universe->items, new_uid, uidlen, unit);
+

+
}
modified libpkg/private/pkg_jobs.h
@@ -43,7 +43,6 @@ struct pkg_job_universe_item {
	struct pkg *pkg;
	struct job_pattern *jp;
	int priority;
-
	struct pkg *reinstall;
	UT_hash_handle hh;
	struct pkg_job_universe_item *next, *prev;
};
@@ -151,6 +150,12 @@ int pkg_jobs_universe_process_package(struct pkg_jobs_universe *universe,
	struct pkg *pkg);

/*
+
 * Add a package to the universe and store resulting item in `result`
+
 */
+
int pkg_jobs_process_universe(struct pkg_jobs_universe *universe,
+
	struct pkg *pkg, struct pkg_job_universe_item **result);
+

+
/*
 * Add a universe item with package to the request
 */
void pkg_jobs_add_req(struct pkg_jobs *j, const char *uid,
@@ -168,4 +173,17 @@ bool pkg_jobs_universe_seen(struct pkg_jobs_universe *universe,
struct pkg_job_universe_item * pkg_jobs_universe_find(struct pkg_jobs_universe
	*universe, const char *uid);

+
/*
+
 * Add a single package to the universe
+
 */
+
int pkg_jobs_universe_add_pkg(struct pkg_jobs_universe *universe,
+
	struct pkg *pkg, bool force, struct pkg_job_universe_item **found);
+

+
/*
+
 * Change uid for universe item
+
 */
+
void pkg_jobs_universe_change_uid(struct pkg_jobs_universe *universe,
+
	struct pkg_job_universe_item *unit,
+
	const char *new_uid, size_t uidlen, bool update_rdeps);
+

#endif /* PKG_JOBS_H_ */