Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
upgrade: fix and simplify detection of upgrade requirements
Baptiste Daroussin committed 1 year ago
commit e9ddeea26eb3a8346a8c1ef9bf05f568876d7bd2
parent e12bd6a
4 files changed +51 -72
modified libpkg/pkg.c
@@ -32,6 +32,7 @@ pkg_new(struct pkg **pkg, pkg_t type)
	*pkg = xcalloc(1, sizeof(struct pkg));
	(*pkg)->type = type;
	(*pkg)->rootfd = -1;
+
	(*pkg)->list_sorted = false;

	return (EPKG_OK);
}
@@ -1700,9 +1701,27 @@ pkg_cf_cmp(struct pkg_config_file *a, struct pkg_config_file *b)
{
	return (STREQ(a->path, b->path));
}
+

+
static int
+
char_cmp(const void *a, const void *b) {
+
    return strcmp(*(char **)a, *(char **)b);
+
}
+

void
pkg_lists_sort(struct pkg *p)
{
+
	if (p->list_sorted)
+
		return;
+
	p->list_sorted = true;
+

+
	qsort(p->categories.d, p->categories.len, sizeof(char *), char_cmp);
+
	qsort(p->licenses.d, p->licenses.len, sizeof(char *), char_cmp);
+
	qsort(p->users.d, p->users.len, sizeof(char *), char_cmp);
+
	qsort(p->groups.d, p->groups.len, sizeof(char *), char_cmp);
+
	qsort(p->shlibs_required.d, p->shlibs_required.len, sizeof(char *), char_cmp);
+
	qsort(p->shlibs_provided.d, p->shlibs_provided.len, sizeof(char *), char_cmp);
+
	qsort(p->provides.d, p->provides.len, sizeof(p->provides.d[0]), char_cmp);
+
	qsort(p->requires.d, p->requires.len, sizeof(p->requires.d[0]), char_cmp);
	DL_SORT(p->depends, pkg_dep_cmp);
	DL_SORT(p->files, pkg_file_cmp);
	DL_SORT(p->dirs, pkg_dir_cmp);
modified libpkg/pkg_jobs.c
@@ -1058,8 +1058,6 @@ pkg_jobs_need_upgrade(struct pkghash *system_shlibs, struct pkg *rp, struct pkg
	struct pkg_option *lo = NULL, *ro = NULL;
	struct pkg_dep *ld = NULL, *rd = NULL;
	struct pkg_conflict *lc = NULL, *rc = NULL;
-
	const char **l1;
-
	size_t i;

	/* If no local package, then rp is obviously need to be added */
	if (lp == NULL)
@@ -1185,21 +1183,16 @@ pkg_jobs_need_upgrade(struct pkghash *system_shlibs, struct pkg *rp, struct pkg
		rp->reason = xstrdup("provides changed");
		return (true);
	}
-
	l1 = xcalloc(vec_len(&lp->provides), sizeof (char*));
-
	i = 0;
-
	vec_foreach(lp->provides, j) {
-
		l1[i++] = lp->provides.d[j];
-
	}
-
	i = 0;
-
	vec_foreach(rp->provides, j) {
-
		if (!STREQ(rp->provides.d[j], l1[i])) {
+
	pkg_lists_sort(lp);
+
	pkg_lists_sort(rp);
+

+
	vec_foreach(lp->provides, i) {
+
		if (!STREQ(lp->provides.d[i], rp->provides.d[i])) {
			free(rp->reason);
			rp->reason = xstrdup("provides changed");
-
			free(l1);
			return (true);
		}
	}
-
	free(l1);

	/* Requires */
	if (vec_len(&rp->requires) != vec_len(&lp->requires)) {
@@ -1207,21 +1200,13 @@ pkg_jobs_need_upgrade(struct pkghash *system_shlibs, struct pkg *rp, struct pkg
		rp->reason = xstrdup("requires changed");
		return (true);
	}
-
	l1 = xcalloc(vec_len(&lp->requires), sizeof (char*));
-
	i = 0;
-
	vec_foreach(lp->requires, j) {
-
		l1[i++] = lp->requires.d[j];
-
	}
-
	i = 0;
-
	vec_foreach(rp->requires, j) {
-
		if (!STREQ(rp->requires.d[j], l1[i])) {
+
	vec_foreach(lp->requires, i) {
+
		if (!STREQ(lp->requires.d[i], rp->requires.d[i])) {
			free(rp->reason);
			rp->reason = xstrdup("requires changed");
-
			free(l1);
			return (true);
		}
	}
-
	free(l1);

	/* Finish by the shlibs */
	if (vec_len(&rp->shlibs_provided) != vec_len(&lp->shlibs_provided)) {
@@ -1229,67 +1214,41 @@ pkg_jobs_need_upgrade(struct pkghash *system_shlibs, struct pkg *rp, struct pkg
		rp->reason = xstrdup("provided shared library changed");
		return (true);
	}
-
	l1 = xcalloc(vec_len(&lp->shlibs_provided), sizeof (char*));
-
	i = 0;
-
	vec_foreach(lp->shlibs_provided, j) {
-
		l1[i++] = lp->shlibs_provided.d[j];
-
	}
-
	i = 0;
-
	vec_foreach(rp->shlibs_provided, j) {
-
		if (!STREQ(rp->shlibs_provided.d[j], l1[i])) {
+
	vec_foreach(lp->shlibs_provided, i) {
+
		if (!STREQ(lp->shlibs_provided.d[i], rp->shlibs_provided.d[i])) {
			free(rp->reason);
			rp->reason = xstrdup("provided shared library changed");
-
			free(l1);
			return (true);
		}
-
		i++;
	}
-
	free(l1);

	size_t cntr = vec_len(&rp->shlibs_required);
	size_t cntl = vec_len(&lp->shlibs_required);
-
	if (cntr != cntl) {
+
	if (cntr != cntl & system_shlibs == NULL) {
+
		free(rp->reason);
+
		rp->reason = xstrdup("required shared library changed");
+
		return (true);
+
	}
+
	size_t i, j;
+

+
	for (i = 0, j = 0; i < cntl && j < cntr; i++, j++) {
+
		if (STREQ(lp->shlibs_required.d[i], rp->shlibs_required.d[j]))
+
				continue;
		if (system_shlibs != NULL) {
-
		/*
-
		 * before considering shlibs we need to check if we are running
-
		 * pkgbase
-
		 */
-
			vec_foreach(rp->shlibs_required, i) {
-
				if (pkghash_get(system_shlibs, rp->shlibs_required.d[i]) != NULL)
-
					cntr--;
+
			if (pkghash_get(system_shlibs, lp->shlibs_required.d[i]) != NULL) {
+
				j--;
+
				continue;
			}
-
			vec_foreach(lp->shlibs_required, i) {
-
				if (pkghash_get(system_shlibs, lp->shlibs_required.d[i]) != NULL)
-
					cntl--;
+
			if (pkghash_get(system_shlibs, rp->shlibs_required.d[j]) != NULL) {
+
				i++;
+
				continue;
			}
		}
-
		if (cntr != cntl) {
-
			free(rp->reason);
-
			rp->reason = xstrdup("required shared library changed");
-
			return (true);
-
		}
-
	}
-
	l1 = xcalloc(vec_len(&lp->shlibs_required), sizeof (char*));
-
	i = 0;
-
	vec_foreach(lp->shlibs_required, j) {
-
		if (pkghash_get(system_shlibs, lp->shlibs_required.d[j]) != NULL)
-
			continue;
-
		l1[i++] = lp->shlibs_required.d[j];
-
	}
-
	i = 0;
-
	vec_foreach(rp->shlibs_required, j) {
-
		if (pkghash_get(system_shlibs, rp->shlibs_required.d[j]) != NULL)
-
			continue;
-
		if (!STREQ(rp->shlibs_required.d[j], l1[i])) {
-
			free(rp->reason);
-
			rp->reason = xstrdup("required shared library changed");
-
			free(l1);
-
			return (true);
-
		}
-
		i++;
+
		free(rp->reason);
+
		rp->reason = xstrdup("required shared library changed");
+
		return (true);
+
		break;
	}
-
	free(l1);
-

	return (false);
}

modified libpkg/private/pkg.h
@@ -178,6 +178,7 @@ struct pkg {
	bool		 locked;
	bool		 automatic;
	bool		 vital;
+
	bool		 list_sorted;
	int64_t		 id;
	xstring		*scripts[PKG_NUM_SCRIPTS];
	charv_t	 lua_scripts[PKG_NUM_LUA_SCRIPTS];
modified tests/frontend/test_environment.sh.in
@@ -75,13 +75,13 @@ bin_meta() {
			XABI=FreeBSD:13:armv6
			XALTABI=freebsd:13:armv6:32:el:eabi:hardfp
			XFreeBSD_version=1304000
-
			Xshlibs_required="libgcc_s.so.1 libc.so.7"
+
			Xshlibs_required="libc.so.7 libgcc_s.so.1"
			;;
		*freebsd-armv7.bin)
			XABI=FreeBSD:14:armv7
			XALTABI=freebsd:14:armv7:32:el:eabi:hardfp
			XFreeBSD_version=1401000
-
			Xshlibs_required="libgcc_s.so.1 libc.so.7"
+
			Xshlibs_required="libc.so.7 libgcc_s.so.1"
			;;
		*freebsd-i386.bin)
			XABI=FreeBSD:14:i386