socsvn commit: r254412 - in soc2013/mattbw/backend: . actions query
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Mon Jul 8 12:27:18 UTC 2013
Author: mattbw
Date: Mon Jul 8 12:27:17 2013
New Revision: 254412
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254412
Log:
resolve implemented, mostly, some version quirkiness
Modified:
soc2013/mattbw/backend/actions/resolve.c
soc2013/mattbw/backend/pkgutils.c
soc2013/mattbw/backend/pkgutils.h
soc2013/mattbw/backend/query/core.c
soc2013/mattbw/backend/query/core.h
soc2013/mattbw/backend/query/do.c
soc2013/mattbw/backend/query/match.c
Modified: soc2013/mattbw/backend/actions/resolve.c
==============================================================================
--- soc2013/mattbw/backend/actions/resolve.c Mon Jul 8 12:06:17 2013 (r254411)
+++ soc2013/mattbw/backend/actions/resolve.c Mon Jul 8 12:27:17 2013 (r254412)
@@ -22,11 +22,12 @@
#include "pkg.h"
#include "../db.h" /* db_open_remote */
+#include "../pkgutils.h" /* pkgutils_* */
#include "../query.h" /* query_* */
+#include "../utils.h" /* INTENTIONALLY_IGNORE */
#include "actions.h" /* Prototype */
-static gboolean resolve_id(struct pkgdb *db, PkBackend *backend, gchar *id);
-static gboolean resolve_name(struct pkgdb *db, PkBackend *backend, gchar *name);
+static gboolean emit(struct pkg *pkg, const gchar *id, struct query *q);
/*
* Resolves a package identifier, which may be a full PackageID or a package
@@ -36,59 +37,31 @@
resolve_thread(PkBackend *backend)
{
gboolean success;
- struct pkgdb *db;
- gchar **package_ids;
+ struct query_source s;
+ struct query_target t;
- success = TRUE;
+ s.type = QUERY_BACKEND_MIXED;
+ t.type = QUERY_EMIT;
+ t.data.emit.load_flags = PKG_LOAD_BASIC;
+ t.data.emit.f = emit;
- package_ids = pk_backend_get_strv(backend, "package_ids");
+ success = query_do(backend, &s, &t);
- db = NULL;
- if (db_open_remote(&db, backend) == TRUE) {
- gchar **id_p;
-
- for (id_p = package_ids; *id_p != NULL && success; id_p++) {
- if (pk_package_id_check(*id_p) == TRUE)
- success = resolve_id(db, backend, *id_p);
- else
- success = resolve_name(db, backend, *id_p);
- }
- } else
- success = FALSE;
-
- pkgdb_close(db);
- pk_backend_finished(backend);
+ (void)pk_backend_finished(backend);
return success;
}
static gboolean
-resolve_id(struct pkgdb *db, PkBackend *backend, gchar *id)
+emit(struct pkg *pkg, const gchar *id, struct query *q)
{
+ PkBackend *backend;
- /* TODO: implement */
-
- /*struct query_target t;
-
- t.type = QUERY_EMIT;
- t.data.emit.load_flags = load_flags;
- t.data.emit.f = emitter;
-
- return query_do(backend, &t, query_find_match);*/
+ INTENTIONALLY_IGNORE(id);
+ backend = query_backend(q);
- (void)db;
- (void)backend;
- (void)id;
- return FALSE;
-}
+ query_set_percentage(q, 0);
+ pkgutils_emit(pkg, backend, pkgutils_pkg_current_state(pkg));
+ query_set_percentage(q, 100);
-static gboolean
-resolve_name(struct pkgdb *db, PkBackend *backend, gchar *name)
-{
-
- /* TODO: implement */
- (void)db;
- (void)backend;
- (void)name;
- return FALSE;
+ return TRUE;
}
-
Modified: soc2013/mattbw/backend/pkgutils.c
==============================================================================
--- soc2013/mattbw/backend/pkgutils.c Mon Jul 8 12:06:17 2013 (r254411)
+++ soc2013/mattbw/backend/pkgutils.c Mon Jul 8 12:27:17 2013 (r254412)
@@ -28,6 +28,17 @@
static const char *repo_of_remote(struct pkg *pkg);
/*
+ * Infers the correct PkInfoEnum to emit for this package for its current state.
+ */
+PkInfoEnum
+pkgutils_pkg_current_state(struct pkg *pkg)
+{
+
+ return (pkg_type(pkg) == PKG_INSTALLED ?
+ PK_INFO_ENUM_INSTALLED : PK_INFO_ENUM_AVAILABLE);
+}
+
+/*
* Infers the correct PkInfoEnum to emit for this package if it is being
* installed, mainly from its current installation information.
*/
Modified: soc2013/mattbw/backend/pkgutils.h
==============================================================================
--- soc2013/mattbw/backend/pkgutils.h Mon Jul 8 12:06:17 2013 (r254411)
+++ soc2013/mattbw/backend/pkgutils.h Mon Jul 8 12:27:17 2013 (r254412)
@@ -25,6 +25,7 @@
#include "pk-backend.h"
#include "pkg.h"
+PkInfoEnum pkgutils_pkg_current_state(struct pkg *pkg);
PkInfoEnum pkgutils_pkg_install_state(struct pkg *pkg);
const char *pkgutils_pk_repo_of(struct pkg *pkg);
gchar *pkgutils_pkg_to_id(struct pkg *pkg);
Modified: soc2013/mattbw/backend/query/core.c
==============================================================================
--- soc2013/mattbw/backend/query/core.c Mon Jul 8 12:06:17 2013 (r254411)
+++ soc2013/mattbw/backend/query/core.c Mon Jul 8 12:27:17 2013 (r254412)
@@ -76,13 +76,55 @@
}
/*
- * Performs a package database query against a (potentially partial)
- * PackageID, retrieving the matched package and its full PackageID.
- *
- * The exact type of query depends on the repository given.
+ * For adapting an emitter function into one that solves and applies a job.
*/
gboolean
-query_find_match(struct query *q)
+query_emit_to_job(struct pkg *pkg, const gchar *id, struct query *q)
+{
+ gboolean success;
+ struct pkg_jobs *jobs;
+ PkBackend *backend;
+
+ INTENTIONALLY_IGNORE(id);
+
+ success = FALSE;
+ jobs = NULL;
+
+ if (q == NULL)
+ goto cleanup;
+
+ backend = query_backend(q);
+
+ if (pkg_jobs_new(&jobs, q->t->data.job.type, q->db) != EPKG_OK) {
+ (void)pk_backend_error_code(backend,
+ PK_ERROR_ENUM_INTERNAL_ERROR,
+ "could not init pkg_jobs");
+ goto cleanup;
+ }
+ if (jobs_repo_from_query(jobs, q) != EPKG_OK) {
+ (void)pk_backend_error_code(backend,
+ PK_ERROR_ENUM_REPO_NOT_FOUND,
+ "could not set repo");
+ goto cleanup;
+ }
+ if (jobs_add_pkg(jobs, MATCH_EXACT, pkg) != EPKG_OK) {
+ (void)pk_backend_error_code(backend,
+ PK_ERROR_ENUM_INTERNAL_ERROR,
+ "could not add to job");
+ goto cleanup;
+ }
+ success = q->t->data.job.f(jobs, q);
+
+cleanup:
+ pkg_jobs_free(jobs);
+ return success;
+}
+
+/*
+ * Runs an assembled query.
+ */
+gboolean
+query_run(struct query *q)
{
gboolean success;
gboolean try_local;
@@ -151,61 +193,6 @@
}
/*
- * For adapting an emitter function into one that solves and applies a job.
- */
-gboolean
-query_emit_to_job(struct pkg *pkg, const gchar *id, struct query *q)
-{
- gboolean success;
- struct pkg_jobs *jobs;
- PkBackend *backend;
-
- INTENTIONALLY_IGNORE(id);
-
- success = FALSE;
- jobs = NULL;
-
- if (q == NULL)
- goto cleanup;
-
- backend = query_backend(q);
-
- if (pkg_jobs_new(&jobs, q->t->data.job.type, q->db) != EPKG_OK) {
- (void)pk_backend_error_code(backend,
- PK_ERROR_ENUM_INTERNAL_ERROR,
- "could not init pkg_jobs");
- goto cleanup;
- }
- if (jobs_repo_from_query(jobs, q) != EPKG_OK) {
- (void)pk_backend_error_code(backend,
- PK_ERROR_ENUM_REPO_NOT_FOUND,
- "could not set repo");
- goto cleanup;
- }
- if (jobs_add_pkg(jobs, MATCH_EXACT, pkg) != EPKG_OK) {
- (void)pk_backend_error_code(backend,
- PK_ERROR_ENUM_INTERNAL_ERROR,
- "could not add to job");
- goto cleanup;
- }
- success = q->t->data.job.f(jobs, q);
-
-cleanup:
- pkg_jobs_free(jobs);
- return success;
-}
-
-/*
- * Runs an assembled query.
- */
-gboolean
-query_run(struct query *q)
-{
-
- return q->s->body(q);
-}
-
-/*
* Creates a struct query for the given backend, database, source and target.
*
* Usually you'll want to use "query_do" instead of calling this directly.
Modified: soc2013/mattbw/backend/query/core.h
==============================================================================
--- soc2013/mattbw/backend/query/core.h Mon Jul 8 12:06:17 2013 (r254411)
+++ soc2013/mattbw/backend/query/core.h Mon Jul 8 12:27:17 2013 (r254412)
@@ -34,7 +34,8 @@
enum query_source_type {
QUERY_SINGLE_ID,
QUERY_SINGLE_NAME,
- QUERY_BACKEND_IDS
+ QUERY_BACKEND_IDS,
+ QUERY_BACKEND_MIXED
};
enum query_target_type {
@@ -73,7 +74,6 @@
PkBackend *query_backend(struct query *q);
gboolean query_emit_to_job(struct pkg *pkg, const gchar *id, struct query *q);
-gboolean query_find_match(struct query *q);
gboolean query_run(struct query *q);
struct query *query_init(PkBackend *backend, struct pkgdb *db, struct query_source *s, struct query_target *t);
void query_free(struct query **q_p);
Modified: soc2013/mattbw/backend/query/do.c
==============================================================================
--- soc2013/mattbw/backend/query/do.c Mon Jul 8 12:06:17 2013 (r254411)
+++ soc2013/mattbw/backend/query/do.c Mon Jul 8 12:27:17 2013 (r254412)
@@ -49,6 +49,7 @@
if (db_open_remote(&db, backend) == TRUE) {
switch (s->type) {
case QUERY_BACKEND_IDS:
+ case QUERY_BACKEND_MIXED:
success = do_backend_ids(backend, db, s, t);
break;
case QUERY_SINGLE_NAME:
@@ -81,15 +82,20 @@
success = TRUE;
package_ids = pk_backend_get_strv(backend, "package_ids");
- new_s.type = QUERY_SINGLE_ID;
new_s.total = g_strv_length(package_ids);
- new_s.body = s->body;
for (new_s.position = 0;
new_s.position < new_s.total && success;
(new_s.position)++) {
new_s.data.single = package_ids[new_s.position];
+ /* Treat non-PackageIDs as pkgng package names, if allowed */
+ if (s->type == QUERY_BACKEND_IDS ||
+ pk_package_id_check(new_s.data.single) == TRUE)
+ new_s.type = QUERY_SINGLE_ID;
+ else
+ new_s.type = QUERY_SINGLE_NAME;
+
success = do_single(backend, db, &new_s, t);
}
Modified: soc2013/mattbw/backend/query/match.c
==============================================================================
--- soc2013/mattbw/backend/query/match.c Mon Jul 8 12:06:17 2013 (r254411)
+++ soc2013/mattbw/backend/query/match.c Mon Jul 8 12:27:17 2013 (r254412)
@@ -45,7 +45,6 @@
struct query_target t;
s.type = QUERY_BACKEND_IDS;
- s.body = query_find_match;
t.type = QUERY_EMIT;
t.data.emit.load_flags = load_flags;
@@ -67,7 +66,6 @@
struct query_target t;
s.type = QUERY_BACKEND_IDS;
- s.body = query_find_match;
t.type = QUERY_JOB;
t.data.job.type = type;
More information about the svn-soc-all
mailing list