[PATCH] libopkg: prefer installable packages

=3D?UTF-8?q?Bj=3DC3=3DB8rn=3D20Mork?=3D bjorn at mork.no
Thu Oct 17 07:44:38 EDT 2019


Give packages with unresolvable dependencies a lower priority
when selecting the best candidate.  This makes it possible
to have multiple kmod package repos with higher versions
than the installed kernel, and still be able to install
the matching versions.

Signed-off-by: Bj=C3=B8rn Mork <bjorn at mork.no>
---
 libopkg/pkg.c | 24 ++++++++++++++++++++++++
 libopkg/pkg.h |  1 +
 2 files changed, 25 insertions(+)

diff --git a/libopkg/pkg.c b/libopkg/pkg.c
index e5bfe6f61b67..e9261e45019e 100644
--- a/libopkg/pkg.c
+++ b/libopkg/pkg.c
@@ -1084,10 +1084,31 @@ int pkg_version_satisfied(pkg_t * it, pkg_t * ref, =
const char *op)
 	return 0;
 }
=20
+int pkg_is_installable(const pkg_t *pkg)
+{
+	compound_depend_t *dep =3D pkg_get_depends((pkg_t *)pkg, DEPEND);
+
+	for (; dep && dep->type; dep++) {
+		int i, ok =3D 0;
+		if (dep->type !=3D DEPEND)
+			continue;
+		for (i =3D 0; i < dep->possibility_count; i++) {
+			if (pkg_dependence_satisfiable(dep->possibilities[i])) {
+				ok =3D 1;
+				break;
+			}
+		}
+		if (!ok)
+			return 0;
+	}
+	return 1;
+}
+
 int pkg_name_version_and_architecture_compare(const void *p1, const void *=
p2)
 {
 	const pkg_t * a =3D *(const pkg_t **)p1;
 	const pkg_t * b =3D *(const pkg_t **)p2;
+	int installcmp;
 	int namecmp;
 	int vercmp;
 	int arch_prio1, arch_prio2;
@@ -1097,6 +1118,9 @@ int pkg_name_version_and_architecture_compare(const v=
oid *p1, const void *p2)
 		return 0;
 	}
=20
+	installcmp =3D pkg_is_installable(a) - pkg_is_installable(b);
+	if (installcmp)
+		return installcmp;
 	namecmp =3D strcmp(a->name, b->name);
 	if (namecmp)
 		return namecmp;
diff --git a/libopkg/pkg.h b/libopkg/pkg.h
index 600fc9eaa25c..3ab48cae3813 100644
--- a/libopkg/pkg.h
+++ b/libopkg/pkg.h
@@ -248,6 +248,7 @@ int pkg_merge(pkg_t * oldpkg, pkg_t * newpkg);
 char *pkg_version_str_alloc(pkg_t * pkg);
=20
 int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
+int pkg_is_installable(const pkg_t * pkg);
 int pkg_name_version_and_architecture_compare(const void *a, const void *b=
);
 int abstract_pkg_name_compare(const void *a, const void *b);
=20
--=20
2.20.1


--=-=-=
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

--=-=-=--




More information about the openwrt-devel mailing list