Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Backout support for provides/requires for pkg add
Baptiste Daroussin committed 2 years ago
commit 537d39eadf27a9b116e5ed168efdcb29ce1dfa39
parent b2bd9ce
5 files changed +56 -206
modified libpkg/pkg_add.c
@@ -956,21 +956,45 @@ pkg_extract_finalize(struct pkg *pkg, tempdirs_t *tempdirs)
	return (EPKG_OK);
}

-
static bool
-
should_append_pkg(pkg_chain_t *localpkgs, struct pkg *p)
+
static char *
+
pkg_globmatch(char *pattern, const char *name)
{
-
	/* only keep the highest version is we fine one */
-
	tll_foreach(*localpkgs, lp) {
-
		if (strcmp(lp->item->name, p->name) == 0) {
-
			if (pkg_version_cmp(lp->item->version, p->version) == -1) {
-
				tll_remove_and_free(*localpkgs, lp, pkg_free);
-
				return (true);
-
			}
-
			return (false);
+
	glob_t g;
+
	int i;
+
	char *buf, *buf2;
+
	char *path = NULL;
+

+
	if (glob(pattern, 0, NULL, &g) == GLOB_NOMATCH) {
+
		globfree(&g);
+

+
		return (NULL);
+
	}
+

+
	for (i = 0; i < g.gl_pathc; i++) {
+
		/* the version starts here */
+
		buf = strrchr(g.gl_pathv[i], '-');
+
		if (buf == NULL)
+
			continue;
+
		buf2 = strrchr(g.gl_pathv[i], '/');
+
		if (buf2 == NULL)
+
			buf2 = g.gl_pathv[i];
+
		else
+
			buf2++;
+
		/* ensure we have match the proper name */
+
		if (strncmp(buf2, name, buf - buf2) != 0)
+
			continue;
+
		if (path == NULL) {
+
			path = g.gl_pathv[i];
+
			continue;
		}
+
		if (pkg_version_cmp(path, g.gl_pathv[i]) == 1)
+
			path = g.gl_pathv[i];
	}
-
	/* none found we should append */
-
	return (true);
+
	if (path)
+
		path = xstrdup(path);
+
	globfree(&g);
+

+
	return (path);
}

static int
@@ -981,13 +1005,10 @@ pkg_add_check_pkg_archive(struct pkgdb *db, struct pkg *pkg,
	int	ret, retcode;
	struct pkg_dep	*dep = NULL;
	char	bd[MAXPATHLEN], *basedir = NULL;
+
	char	dpath[MAXPATHLEN], *ppath;
	const char	*ext = NULL;
	struct pkg	*pkg_inst = NULL;
	bool	fromstdin;
-
	pkg_chain_t localpkgs = tll_init();
-
	struct pkghash *lpkgs = NULL;
-
	struct pkghash *provides = NULL;
-
	struct pkghash *shlibs_provides = NULL;

	arch = pkg->abi != NULL ? pkg->abi : pkg->arch;

@@ -1041,39 +1062,9 @@ pkg_add_check_pkg_archive(struct pkgdb *db, struct pkg *pkg,

	retcode = EPKG_FATAL;
	pkg_emit_add_deps_begin(pkg);
-
	if (!fromstdin) {
-
		glob_t g;
-
		char *pattern;
-

-
		xasprintf(&pattern, "%s/*%s" , bd, ext);
-
		if (glob(pattern, 0, NULL, &g) == 0) {
-
			for (int i = 0; i <g.gl_pathc; i++) {
-
				struct pkg *p = NULL;
-
				if (pkg_open(&p, g.gl_pathv[i],
-
				    PKG_OPEN_MANIFEST_COMPACT) == EPKG_OK) {
-
					if (should_append_pkg(&localpkgs, p)) {
-
						p->repopath = xstrdup(g.gl_pathv[i]);
-
						tll_push_back(localpkgs, p);
-
					}
-
				}
-
			}
-
		}
-
		globfree(&g);
-
		free(pattern);
-
		tll_foreach(localpkgs, p) {
-
			pkghash_safe_add(lpkgs, p->item->name, xstrdup(p->item->repopath), NULL);
-
			tll_foreach(p->item->shlibs_provided, sp) {
-
				pkghash_safe_add(shlibs_provides, sp->item, xstrdup(p->item->repopath), free);
-
			}
-
			tll_foreach(p->item->provides, sp) {
-
				pkghash_safe_add(provides, sp->item, xstrdup(p->item->repopath), free);
-
			}
-
		}
-
		tll_free_and_free(localpkgs, pkg_free);
-
	}

	while (pkg_deps(pkg, &dep) == EPKG_OK) {
-
		pkghash_entry *founddep = NULL;
+
		dpath[0] = '\0';

		if (pkg_is_installed(db, dep->name) == EPKG_OK)
			continue;
@@ -1085,76 +1076,28 @@ pkg_add_check_pkg_archive(struct pkgdb *db, struct pkg *pkg,
			continue;
		}

-
		if ((founddep = pkghash_get(lpkgs, dep->name)) == NULL) {
-
			pkg_emit_missing_dep(pkg, dep);
-
			if ((flags & PKG_ADD_FORCE_MISSING) == 0)
-
				goto cleanup;
-
			continue;
-
		}
-

-
		if ((flags & PKG_ADD_UPGRADE) == 0 &&
-
				access(founddep->value, F_OK) == 0) {
-
			ret = pkg_add(db, founddep->value, PKG_ADD_AUTOMATIC, location);
-

-
			if (ret != EPKG_OK)
-
				goto cleanup;
-
		} else {
-
			pkg_emit_missing_dep(pkg, dep);
-
			if ((flags & PKG_ADD_FORCE_MISSING) == 0)
-
				goto cleanup;
-
		}
-
	}
-

-
	tll_foreach(pkg->shlibs_required, s) {
-
		pkghash_entry *founddep = NULL;
-
		if (pkgdb_is_shlib_provided(db, s->item))
-
			continue;
-

-
		if (fromstdin) {
-
			pkg_emit_error("Missing shlib dependency: %s", s->item);
-
			if ((flags & PKG_ADD_FORCE_MISSING) == 0)
-
				goto cleanup;
-
			continue;
-
		}
-
		if ((founddep = pkghash_get(shlibs_provides, s->item)) == NULL) {
-
			pkg_emit_error("Missing shlib dependency: %s", s->item);
-
			if ((flags & PKG_ADD_FORCE_MISSING) == 0)
-
				goto cleanup;
-
			continue;
+
		if (dep->version != NULL && dep->version[0] != '\0') {
+
			snprintf(dpath, sizeof(dpath), "%s/%s-%s%s", bd,
+
				dep->name, dep->version, ext);
		}
-
		if ((flags & PKG_ADD_UPGRADE) == 0 &&
-
				access(founddep->value, F_OK) == 0) {
-
			ret = pkg_add(db, founddep->value, PKG_ADD_AUTOMATIC, location);

-
			if (ret != EPKG_OK)
-
				goto cleanup;
-
		} else {
-
			pkg_emit_missing_dep(pkg, dep);
-
			if ((flags & PKG_ADD_FORCE_MISSING) == 0)
-
				goto cleanup;
+
		if (strlen(dpath) == 0 || access(dpath, F_OK) != 0) {
+
			snprintf(dpath, sizeof(dpath), "%s/%s-*%s", bd,
+
			    dep->name, ext);
+
			ppath = pkg_globmatch(dpath, dep->name);
+
			if (ppath == NULL) {
+
				pkg_emit_missing_dep(pkg, dep);
+
				if ((flags & PKG_ADD_FORCE_MISSING) == 0)
+
					goto cleanup;
+
				continue;
+
			}
+
			strlcpy(dpath, ppath, sizeof(dpath));
+
			free(ppath);
		}
-
	}
-

-
	tll_foreach(pkg->requires, s) {
-
		pkghash_entry *founddep = NULL;
-
		if (pkgdb_is_provided(db, s->item))
-
			continue;

-
		if (fromstdin) {
-
			pkg_emit_error("Missing require dependency: %s", s->item);
-
			if ((flags & PKG_ADD_FORCE_MISSING) == 0)
-
				goto cleanup;
-
			continue;
-
		}
-
		if ((founddep = pkghash_get(provides, s->item)) == NULL) {
-
			pkg_emit_error("Missing require dependency: %s", s->item);
-
			if ((flags & PKG_ADD_FORCE_MISSING) == 0)
-
				goto cleanup;
-
			continue;
-
		}
		if ((flags & PKG_ADD_UPGRADE) == 0 &&
-
				access(founddep->value, F_OK) == 0) {
-
			ret = pkg_add(db, founddep->value, PKG_ADD_AUTOMATIC, location);
+
				access(dpath, F_OK) == 0) {
+
			ret = pkg_add(db, dpath, PKG_ADD_AUTOMATIC, location);

			if (ret != EPKG_OK)
				goto cleanup;
@@ -1167,9 +1110,6 @@ pkg_add_check_pkg_archive(struct pkgdb *db, struct pkg *pkg,

	retcode = EPKG_OK;
cleanup:
-
	pkghash_destroy(lpkgs);
-
	pkghash_destroy(provides);
-
	pkghash_destroy(shlibs_provides);
	pkg_emit_add_deps_finished(pkg);

	return (retcode);
modified libpkg/pkg_manifest.c
@@ -1053,7 +1053,7 @@ pkg_emit_object(struct pkg *pkg, short flags)
	if (seq)
		ucl_object_insert_key(top, seq, "groups", 6, false);

-
	pkg_debug(4, "Emitting shibs_required %zu\n", tll_length(pkg->shlibs_required));
+
	pkg_debug(4, "Emitting shibs_required");
	seq = NULL;
	tll_foreach(pkg->shlibs_required, s) {
		if (seq == NULL)
modified libpkg/pkgdb.c
@@ -3032,53 +3032,3 @@ pkgdb_is_dir_used(struct pkgdb *db, struct pkg *p, const char *dir, int64_t *res

	return (EPKG_OK);
}
-

-
bool
-
pkgdb_is_shlib_provided(struct pkgdb *db, const char *req)
-
{
-
	sqlite3_stmt *stmt;
-
	int ret;
-
	bool found = false;
-

-
	const char *sql = ""
-
		"select package_id from pkg_shlibs_provided INNER JOIN shlibs "
-
		"on pkg_shlibs_provided.shlib_id = shlibs.id "
-
		"where shlibs.name=?1" ;
-

-
	stmt = prepare_sql(db->sqlite, sql);
-
	if (stmt == NULL)
-
		return (false);
-

-
	sqlite3_bind_text(stmt, 1, req, -1, SQLITE_TRANSIENT);
-
	ret = sqlite3_step(stmt);
-
	if (ret == SQLITE_ROW)
-
		found = true;
-

-
	sqlite3_finalize(stmt);
-
	return (found);
-
}
-

-
bool
-
pkgdb_is_provided(struct pkgdb *db, const char *req)
-
{
-
	sqlite3_stmt *stmt;
-
	int ret;
-
	bool found = false;
-

-
	const char *sql = ""
-
		"select package_id from pkg_provides INNER JOIN provides "
-
		"on pkg_provides.provide_id = provides.id "
-
		"where provides.provide = ?1" ;
-

-
	stmt = prepare_sql(db->sqlite, sql);
-
	if (stmt == NULL)
-
		return (false);
-

-
	sqlite3_bind_text(stmt, 1, req, -1, SQLITE_TRANSIENT);
-
	ret = sqlite3_step(stmt);
-
	if (ret == SQLITE_ROW)
-
		found = true;
-

-
	sqlite3_finalize(stmt);
-
	return (found);
-
}
modified libpkg/private/pkgdb.h
@@ -176,7 +176,4 @@ void pkgdb_nfs_corruption(sqlite3 *s);
bool pkgdb_file_exists(struct pkgdb *db, const char *path);
struct sqlite3_stmt *prepare_sql(sqlite3 *s, const char *sql);

-
bool pkgdb_is_provided(struct pkgdb *db, const char *req);
-
bool pkgdb_is_shlib_provided(struct pkgdb *db, const char *req);
-

#endif
modified tests/frontend/add.sh
@@ -13,8 +13,6 @@ tests_init \
		add_stdin_missing \
		add_no_version \
		add_no_version_multi \
-
		add_deps_multi \
-
		add_require \
		add_wrong_version

initialize_pkg() {
@@ -256,41 +254,6 @@ EOF
		pkg add final-1.pkg
}

-
add_deps_multi_body() {
-
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 2
-
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg final final 1
-

-
	cat << EOF >> final.ucl
-
deps {
-
	test {
-
		origin = "test";
-
	},
-
}
-
EOF
-
	atf_check -o ignore -s exit:0 pkg create -M test.ucl
-
	atf_check -o ignore -s exit:0 pkg create -M final.ucl
-
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
-
	atf_check -o ignore -s exit:0 pkg create -M test.ucl
-
	atf_check -o "match:.*test-2.*" -e ignore -s exit:0 \
-
		pkg add final-1.pkg
-
}
-

-
add_require_body() {
-
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
-
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg final final 1
-
	cat << EOF >> final.ucl
-
requires: [functionA]
-
EOF
-
	cat << EOF >> test.ucl
-
provides: [functionA]
-
EOF
-

-
	atf_check -o ignore -s exit:0 pkg create -M test.ucl
-
	atf_check  -s exit:0 pkg create -M final.ucl
-
	atf_check -o match:".*test-1.*" -e ignore -s exit:0 \
-
		pkg add final-1.pkg
-
}
-

add_wrong_version_body() {
	for p in test final ; do
		atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg ${p} ${p} 1