Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
groups: implement pkg rquery
Baptiste Daroussin committed 2 years ago
commit 962d40359bb3b0a120f14c52c743daee552fec31
parent b78016f
6 files changed +46 -17
modified libpkg/pkg_jobs.c
@@ -969,6 +969,15 @@ pkg_jobs_guess_upgrade_candidate(struct pkg_jobs *j, const char *pattern)
}

static int
+
pkg_jobs_find_group_upgrade(struct pkg_jobs *j __unused, const char *pattern __unused, match_t m __unused)
+
{
+
	int rc = EPKG_FATAL;
+
	struct pkg_repo_it *it;
+

+
	return (rc);
+
}
+

+
static int
pkg_jobs_find_upgrade(struct pkg_jobs *j, const char *pattern, match_t m)
{
	struct pkg *p = NULL;
@@ -983,6 +992,10 @@ pkg_jobs_find_upgrade(struct pkg_jobs *j, const char *pattern, match_t m)
			PKG_LOAD_ANNOTATIONS|PKG_LOAD_CONFLICTS;
	struct pkg_job_universe_item *unit = NULL;

+
	/* We are looking for groups */
+
	if (*pattern == '@')
+
		return (pkg_jobs_find_group_upgrade(j, pattern, m));
+

	if ((it = pkgdb_repo_query(j->db, pattern, m, j->reponame)) == NULL)
		return (rc);

modified libpkg/pkgdb_query.c
@@ -393,7 +393,10 @@ pkgdb_repo_query_cond(struct pkgdb *db, const char *cond, const char *pattern, m

	tll_foreach(db->repos, cur) {
		if (repo == NULL || strcasecmp(cur->item->name, repo) == 0) {
-
			rit = cur->item->ops->query(cur->item, cond, pattern, match);
+
			if (*pattern == '@')
+
				rit = cur->item->ops->groupquery(cur->item, pattern + 1, match);
+
			else
+
				rit = cur->item->ops->query(cur->item, cond, pattern, match);
			if (rit != NULL)
				pkgdb_it_repo_attach(it, rit);
		}
modified libpkg/private/pkg.h
@@ -498,6 +498,8 @@ struct pkg_repo_ops {
	/* Query repo */
	struct pkg_repo_it * (*query)(struct pkg_repo *,
					const char*, const char *, match_t);
+
	struct pkg_repo_it * (*groupquery)(struct pkg_repo *,
+
					const char*, match_t);
	struct pkg_repo_it * (*shlib_required)(struct pkg_repo *,
					const char *);
	struct pkg_repo_it * (*shlib_provided)(struct pkg_repo *,
modified libpkg/repo/binary/binary.c
@@ -1,13 +1,14 @@
-
/* Copyright (c) 2014, Vsevolod Stakhov
-
 * All rights reserved.
+
/*
+
 * Copyright (c) 2014, Vsevolod Stakhov
+
 * Copyright (c) 2024, Baptiste Daroussin <bapt@FreeBSD.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
-
 *       * Redistributions of source code must retain the above copyright
-
 *         notice, this list of conditions and the following disclaimer.
-
 *       * Redistributions in binary form must reproduce the above copyright
-
 *         notice, this list of conditions and the following disclaimer in the
-
 *         documentation and/or other materials provided with the distribution.
+
 * * Redistributions of source code must retain the above copyright
+
 *   notice, this list of conditions and the following disclaimer.
+
 * * Redistributions in binary form must reproduce the above copyright
+
 *   notice, this list of conditions and the following disclaimer in the
+
 *   documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -32,6 +33,7 @@ struct pkg_repo_ops pkg_repo_binary_ops = {
	.close = pkg_repo_binary_close,
	.update = pkg_repo_binary_update,
	.query = pkg_repo_binary_query,
+
	.groupquery = pkg_repo_binary_groupquery,
	.shlib_provided = pkg_repo_binary_shlib_provide,
	.shlib_required = pkg_repo_binary_shlib_require,
	.provided = pkg_repo_binary_provide,
modified libpkg/repo/binary/binary.h
@@ -1,13 +1,14 @@
-
/* Copyright (c) 2014, Vsevolod Stakhov
-
 * All rights reserved.
+
/*
+
 * Copyright (c) 2014, Vsevolod Stakhov
+
 * Copyright (c) 2024, Baptiste Daroussin <bapt@FreeBSD.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
-
 *       * Redistributions of source code must retain the above copyright
-
 *         notice, this list of conditions and the following disclaimer.
-
 *       * Redistributions in binary form must reproduce the above copyright
-
 *         notice, this list of conditions and the following disclaimer in the
-
 *         documentation and/or other materials provided with the distribution.
+
 * * Redistributions of source code must retain the above copyright
+
 *   notice, this list of conditions and the following disclaimer.
+
 * * Redistributions in binary form must reproduce the above copyright
+
 *   notice, this list of conditions and the following disclaimer in the
+
 *   documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -41,6 +42,8 @@ int pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode);

struct pkg_repo_it *pkg_repo_binary_query(struct pkg_repo *repo,
	const char *cond, const char *pattern, match_t match);
+
struct pkg_repo_it *pkg_repo_binary_groupquery(struct pkg_repo *repo,
+
	const char *pattern, match_t match);
struct pkg_repo_it *pkg_repo_binary_shlib_provide(struct pkg_repo *repo,
	const char *require);
struct pkg_repo_it *pkg_repo_binary_provide(struct pkg_repo *repo,
modified libpkg/repo/binary/query.c
@@ -172,6 +172,12 @@ pkg_repo_binary_group_it_reset(struct pkg_repo_it *it)
}

struct pkg_repo_it *
+
pkg_repo_binary_groupquery(struct pkg_repo *repo, const char *pattern, match_t match)
+
{
+
	return (pkg_repo_binary_groupsearch(repo, pattern, match, FIELD_NAME));
+
}
+

+
struct pkg_repo_it *
pkg_repo_binary_query(struct pkg_repo *repo, const char *cond, const char *pattern, match_t match)
{
	sqlite3 *sqlite = PRIV_GET(repo);
@@ -572,10 +578,10 @@ pkg_repo_binary_groupsearch(struct pkg_repo *repo, const char *pattern, match_t
			break;
		case MATCH_EXACT:
			if (pkgdb_case_sensitive()) {
-
				if (strcmp(cmp, pattern) == 0)
+
				if (strcmp(cmp, pattern) != 0)
					continue;
			} else {
-
				if (strcasecmp(cmp, pattern) == 0)
+
				if (strcasecmp(cmp, pattern) != 0)
					continue;
			}
			break;