Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
upgrade: don't propose to downgrade to solve a provide/require
Baptiste Daroussin committed 20 days ago
commit 14ce865cf605754791dc65f534557052fb02f574
parent 515ff6d
1 file changed +33 -0
modified libpkg/pkg_jobs_universe.c
@@ -412,6 +412,26 @@ pkg_jobs_universe_handle_provide(struct pkg_jobs_universe *universe,
				rpkg = NULL;
				goto provide;
			}
+
			/*
+
			 * Skip the remote package if its version is not
+
			 * higher than the local already in the universe:
+
			 * registering it as a provider would only offer a
+
			 * downgrade candidate to the solver. This happens
+
			 * when several configured repositories ship the
+
			 * same package under different versions (e.g.
+
			 * pkg from FreeBSD-ports vs from FreeBSD-base).
+
			 */
+
			if (unit->pkg->type == PKG_INSTALLED &&
+
			    pkg_version_cmp(rpkg->version,
+
			        unit->pkg->version) <= 0) {
+
				dbg(4, "handle_provide: %s remote (%s) not "
+
				    "newer than local (%s), skipping",
+
				    rpkg->uid, rpkg->version,
+
				    unit->pkg->version);
+
				pkg_free(rpkg);
+
				rpkg = NULL;
+
				goto provide;
+
			}
			if (pkg_jobs_universe_process_item(universe, rpkg,
			    &unit) != EPKG_OK) {
				continue;
@@ -440,6 +460,19 @@ pkg_jobs_universe_handle_provide(struct pkg_jobs_universe *universe,
					rpkg = NULL;
					goto provide;
				}
+
				/* See comment above: avoid registering a
+
				 * downgrade candidate when the local already
+
				 * provides the requirement. */
+
				if (pkg_version_cmp(rpkg->version,
+
				    npkg->version) <= 0) {
+
					dbg(4, "handle_provide: %s remote "
+
					    "(%s) not newer than local (%s), "
+
					    "skipping", rpkg->uid,
+
					    rpkg->version, npkg->version);
+
					pkg_free(rpkg);
+
					rpkg = NULL;
+
					goto provide;
+
				}
				if (pkg_jobs_universe_process_item(universe, rpkg,
						&unit) != EPKG_OK) {
					continue;