Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
solver: prevent rdeps discovery explosion
Baptiste Daroussin committed 2 months ago
commit 5d02e4b4d42b852a171c0c7a63701e56c33fdfa8
parent c9d2db0
2 files changed +14 -4
modified libpkg/pkg_jobs_universe.c
@@ -658,11 +658,20 @@ pkg_jobs_universe_process_item(struct pkg_jobs_universe *universe, struct pkg *p
		rc = pkg_jobs_universe_process_deps(universe, pkg, flags);
		if (rc != EPKG_OK)
			return (rc);
-
		/* Handle reverse depends */
-
		rc = pkg_jobs_universe_process_deps(universe, pkg,
-
			flags|DEPS_FLAG_REVERSE);
-
		if (rc != EPKG_OK)
+
		/*
+
		 * Handle reverse depends, but only when we are not already
+
		 * inside rdeps processing.  Without this guard the universe
+
		 * expands exponentially: target → dep → rdep → dep → rdep …
+
		 * pulling in thousands of unrelated packages.
+
		 */
+
		if (universe->rdeps_depth == 0) {
+
			universe->rdeps_depth++;
+
			rc = pkg_jobs_universe_process_deps(universe, pkg,
+
				flags|DEPS_FLAG_REVERSE);
+
			universe->rdeps_depth--;
+
			if (rc != EPKG_OK)
				return (rc);
+
		}
		/* Provides/requires */
		rc = pkg_jobs_universe_process_shlibs(universe, pkg);
		if (rc != EPKG_OK)
modified libpkg/private/pkg_jobs.h
@@ -110,6 +110,7 @@ struct pkg_jobs_universe {
	pkghash *provides;	/* shlibs, pkg_job_provide */
	struct pkg_jobs *j;
	size_t nitems;
+
	int rdeps_depth;	/* track rdeps recursion to prevent explosion */
};

struct pkg_jobs_conflict_item {