socsvn commit: r256539 - in soc2013/mattbw/backend: . actions jobs query

mattbw at FreeBSD.org mattbw at FreeBSD.org
Sun Aug 25 16:24:37 UTC 2013


Author: mattbw
Date: Sun Aug 25 16:24:36 2013
New Revision: 256539
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256539

Log:
  Fix build, fill in code for GetDepends and GetRequires.
  
  Aside from the inevitable bug and crash fixes forthcoming later tonight,
  this is more or less the main thrust of the implementation of the above
  and the new query code.
  
  The query code rehash has lost some functionality (mainly error and progress
  reporting, which I hope to add back in at the polishing stage), but is now
  markedly more flexible; the code for checking if a package matches a
  query ID is used in the jobs code now, and fragments of a query run are now
  inside the GetDepends/GetRequires code.
  
  Don't expect this code to work yet; I'm committing because it compiles and
  the previous commit doesn't.
  

Modified:
  soc2013/mattbw/backend/Makefile
  soc2013/mattbw/backend/actions/get_depends.c
  soc2013/mattbw/backend/actions/get_details.c
  soc2013/mattbw/backend/actions/get_files.c
  soc2013/mattbw/backend/actions/get_requires.c
  soc2013/mattbw/backend/actions/get_update_detail.c
  soc2013/mattbw/backend/jobs/check.c
  soc2013/mattbw/backend/pkgutils.c
  soc2013/mattbw/backend/pkgutils.h
  soc2013/mattbw/backend/query.h
  soc2013/mattbw/backend/query/core.h
  soc2013/mattbw/backend/query/depends.c
  soc2013/mattbw/backend/query/depends.h
  soc2013/mattbw/backend/query/do.c
  soc2013/mattbw/backend/query/find.c
  soc2013/mattbw/backend/query/id.c
  soc2013/mattbw/backend/query/id.h
  soc2013/mattbw/backend/query/match.c
  soc2013/mattbw/backend/query/match.h
  soc2013/mattbw/backend/query/packages.c
  soc2013/mattbw/backend/query/packages.h
  soc2013/mattbw/backend/utils.c
  soc2013/mattbw/backend/utils.h

Modified: soc2013/mattbw/backend/Makefile
==============================================================================
--- soc2013/mattbw/backend/Makefile	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/Makefile	Sun Aug 25 16:24:36 2013	(r256539)
@@ -51,7 +51,9 @@
 		actions/update_system.c
 
 SRCS+=						\
+		query/depends.c			\
 		query/do.c			\
+		query/find.c			\
 		query/id.c			\
 		query/match.c			\
 		query/packages.c

Modified: soc2013/mattbw/backend/actions/get_depends.c
==============================================================================
--- soc2013/mattbw/backend/actions/get_depends.c	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/actions/get_depends.c	Sun Aug 25 16:24:36 2013	(r256539)
@@ -29,7 +29,7 @@
 
 static const unsigned int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_DEPS;
 
-static bool	emit(struct pkg *pkg, const gchar *id, struct query *q);
+static bool	emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg);
 
 /*
  * The thread that performs a GetDepends operation. Should be invoked by the
@@ -43,19 +43,19 @@
 	assert(backend != NULL);
 
 	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
-	success = query_match_id_to_emitter(backend, LOAD_FLAGS, emit);
+	success = query_do_from_backend_ids(backend, LOAD_FLAGS, emit);
 
 	(void)pk_backend_finished(backend);
 	return success ? TRUE : FALSE;
 }
 
 static bool
-emit(struct pkg *pkg, const gchar *id, struct query *q)
+emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg)
 {
 
+	assert(db != NULL);
+	assert(pkg != NULL);
 	assert(pkg != NULL);
-	assert(id != NULL);
-	assert(q != NULL);
 
-	return query_depends_emit(query_backend(q), pkg, pkg_deps);
+	return query_depends_emit(backend, pkg, pkg_deps, db, LOAD_FLAGS);
 }

Modified: soc2013/mattbw/backend/actions/get_details.c
==============================================================================
--- soc2013/mattbw/backend/actions/get_details.c	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/actions/get_details.c	Sun Aug 25 16:24:36 2013	(r256539)
@@ -25,14 +25,15 @@
 #include "../pk-backend.h"
 #include "pkg.h"
 
+#include "../actions.h"		/* get_details_thread prototype */
 #include "../group.h"		/* group_from_origin */
 #include "../licenses.h"	/* license_from_pkg */
+#include "../pkgutils.h"	/* pkgutils_... */
 #include "../query.h"		/* query_... */
-#include "../actions.h"		/* get_details_thread prototype */
 
 static const unsigned int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_LICENSES;
 
-static bool	emit(struct pkg *pkg, const gchar *id, struct query *q);
+static bool	emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg);
 
 /*
  * The thread that performs a GetDetails operation. Should be invoked by the
@@ -45,7 +46,7 @@
 
 	assert(backend != NULL);
 
-	success = query_match_id_to_emitter(backend, LOAD_FLAGS, emit);
+	success = query_do_from_backend_ids(backend, LOAD_FLAGS, emit);
 	(void)pk_backend_finished(backend);
 	return success ? TRUE : FALSE;
 }
@@ -54,19 +55,18 @@
  * Emits the given package's details. To be used as an iterating function.
  */
 static bool
-emit(struct pkg *pkg, const gchar *id, struct query *q)
+emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg)
 {
 	bool		success;
 	const char     *description;
 	const char     *www;
+	gchar	       *id;
 	int64_t		flatsize;
 	guint		flatsize_u;
 
+	assert(backend != NULL);
+	assert(db != NULL);
 	assert(pkg != NULL);
-	assert(id != NULL);
-	assert(q != NULL);
-
-	query_set_percentage(q, 0);
 
 	/* Information not already part of the PackageID */
 	description = www = NULL;
@@ -78,7 +78,9 @@
 
 	flatsize_u = (guint)CLAMP(flatsize, 0, G_MAXUINT);
 
-	success = pk_backend_details(query_backend(q),
+	id = pkgutils_pkg_to_id(pkg);
+
+	success = pk_backend_details(backend,
 	    id,
 	    license_name_from_pkg(pkg),
 	    group_of_pkg(pkg),
@@ -86,6 +88,7 @@
 	    www,
 	    flatsize_u) == TRUE;
 
-	query_set_percentage(q, 100);
+	g_free(id);
+
 	return success;
 }

Modified: soc2013/mattbw/backend/actions/get_files.c
==============================================================================
--- soc2013/mattbw/backend/actions/get_files.c	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/actions/get_files.c	Sun Aug 25 16:24:36 2013	(r256539)
@@ -26,11 +26,12 @@
 #include "pkg.h"
 
 #include "../actions.h"		/* get_files_thread prototype */
+#include "../pkgutils.h"	/* pkgutils_... */
 #include "../query.h"		/* query_... */
 
 static const unsigned int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_FILES;
 
-static bool	emit(struct pkg *pkg, const gchar *id, struct query *q);
+static bool	emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg);
 
 /*
  * The thread that performs a GetFiles operation. Should be invoked by the
@@ -44,7 +45,7 @@
 	assert(backend != NULL);
 
 	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
-	success = query_match_id_to_emitter(backend, LOAD_FLAGS, emit);
+	success = query_do_from_backend_ids(backend, LOAD_FLAGS, emit);
 
 	(void)pk_backend_finished(backend);
 	return success ? TRUE : FALSE;
@@ -54,17 +55,15 @@
  * Emits the given package's files. To be used as an iterating function.
  */
 static bool
-emit(struct pkg *pkg, const gchar *id, struct query *q)
+emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg)
 {
 	bool		success;
 	struct pkg_file *file;
 	struct sbuf    *sb;
 
+	assert(backend != NULL);
+	assert(db != NULL);
 	assert(pkg != NULL);
-	assert(id != NULL);
-	assert(q != NULL);
-
-	query_set_percentage(q, 0);
 
 	success = false;
 	file = NULL;
@@ -80,22 +79,26 @@
 		sbuf_printf(sb, ";%s", pkg_file_path(file));
 
 	if (sbuf_finish(sb) != 0)
-		(void)pk_backend_error_code(query_backend(q),
+		(void)pk_backend_error_code(backend,
 		    PK_ERROR_ENUM_INTERNAL_ERROR,
 		    "couldn't construct filename string");
 	else {
 		char           *filenames;
+		gchar	       *id;
 
 		filenames = sbuf_data(sb);
 		/* Skip over any initial ; */
 		if (filenames[0] == ';')
 			filenames++;
 
-		success = (pk_backend_files(query_backend(q), id, filenames) ==
+		id = pkgutils_pkg_to_id(pkg);
+
+		success = (pk_backend_files(backend, id, filenames) ==
 		    TRUE);
+
+		g_free(id);
 	}
 
 	sbuf_delete(sb);
-	query_set_percentage(q, 100);
 	return success;
 }

Modified: soc2013/mattbw/backend/actions/get_requires.c
==============================================================================
--- soc2013/mattbw/backend/actions/get_requires.c	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/actions/get_requires.c	Sun Aug 25 16:24:36 2013	(r256539)
@@ -29,7 +29,7 @@
 
 static const unsigned int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_RDEPS;
 
-static bool	emit(struct pkg *pkg, const gchar *id, struct query *q);
+static bool	emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg);
 
 /*
  * The thread that performs a GetRequires operation. Should be invoked by the
@@ -43,19 +43,19 @@
 	assert(backend != NULL);
 
 	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
-	success = query_match_id_to_emitter(backend, LOAD_FLAGS, emit);
+	success = query_do_from_backend_ids(backend, LOAD_FLAGS, emit);
 
 	(void)pk_backend_finished(backend);
 	return success ? TRUE : FALSE;
 }
 
 static bool
-emit(struct pkg *pkg, const gchar *id, struct query *q)
+emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg)
 {
 
+	assert(backend != NULL);
+	assert(db != NULL);
 	assert(pkg != NULL);
-	assert(id != NULL);
-	assert(q != NULL);
 
-	return query_depends_emit(query_backend(q), pkg, pkg_rdeps);
+	return query_depends_emit(backend, pkg, pkg_rdeps, db, LOAD_FLAGS);
 }

Modified: soc2013/mattbw/backend/actions/get_update_detail.c
==============================================================================
--- soc2013/mattbw/backend/actions/get_update_detail.c	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/actions/get_update_detail.c	Sun Aug 25 16:24:36 2013	(r256539)
@@ -28,34 +28,30 @@
 #include "../query.h"		/* query_..., struct query */
 #include "../utils.h"		/* ERR */
 
-static bool	emit(struct pkg *pkg, const gchar *id, struct query *q);
+static bool	emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg);
 
 gboolean
 get_update_detail_thread(PkBackend *backend)
 {
 	bool		success;
 
-	success = query_match_id_to_emitter(backend, PKG_LOAD_BASIC, emit);
+	success = query_do_from_backend_ids(backend, PKG_LOAD_BASIC, emit);
 	(void)pk_backend_finished(backend);
 	return success ? TRUE : FALSE;
 }
 
 static bool
-emit(struct pkg *pkg, const gchar *id, struct query *q)
+emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg)
 {
 	bool		success;
 	const char     *origin;
-	PkBackend      *backend;
 	struct pkg     *old;
-	struct pkgdb   *db;
 
+	assert(backend != NULL);
+	assert(db != NULL);
 	assert(pkg != NULL);
-	assert(id != NULL);
-	assert(q != NULL);
 
-	db = query_db(q);
-	backend = query_backend(q);
-	success = FALSE;
+	success = false;
 
 	/* See if there's a version of this package already installed */
 	origin = NULL;
@@ -65,21 +61,24 @@
 	pkgutils_add_old_version(db, pkg, &old);
 	if (old != NULL && pkg_version_change(pkg) == PKG_UPGRADE) {
 		const char     *update_text;
+		gchar	       *new_id;
 		gchar	       *old_id;
 
+		new_id = pkgutils_pkg_to_id(pkg);
 		old_id = pkgutils_pkg_to_id(old);
 
 		/* TODO: elaborate on this */
 		update_text = "new version";
 
-		(void)pk_backend_update_detail(backend, id, old_id, NULL, NULL,
-		    NULL, NULL, PK_RESTART_ENUM_NONE, update_text, NULL,
+		(void)pk_backend_update_detail(backend, new_id, old_id, NULL,
+		    NULL, NULL, NULL, PK_RESTART_ENUM_NONE, update_text, NULL,
 		    PK_UPDATE_STATE_ENUM_UNKNOWN, NULL, NULL);
 		/* Phew */
 
+		g_free(new_id);
 		g_free(old_id);
 
-		success = TRUE;
+		success = true;
 	}
 
 	pkg_free(old);

Modified: soc2013/mattbw/backend/jobs/check.c
==============================================================================
--- soc2013/mattbw/backend/jobs/check.c	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/jobs/check.c	Sun Aug 25 16:24:36 2013	(r256539)
@@ -29,12 +29,11 @@
 
 #include "../utils.h"		/* ERR */
 #include "../pkgutils.h"	/* pkgutils_... */
+#include "../query.h"		/* query_... */
 #include "check.h"		/* jobs_check_... */
 
-static bool jobs_check_id_on_package(struct pkg *pkg, gchar **split_id, const char *name, const char *version);
-static bool jobs_check_split_package_ids(struct pkg_jobs *jobs, gchar ***id_splits, guint count, bool reject_non_updates);
-static gchar ***make_package_id_splits(gchar **package_ids, guint count);
-static void free_package_id_splits(gchar ****id_splits_p, guint count);
+static bool jobs_check_id_on_package(struct pkg *pkg, struct query_id *query_id, const char *namever);
+static bool jobs_check_query_ids(struct pkg_jobs *jobs, struct query_id *query_ids, guint count, bool reject_non_updates);
 
 /* Checks a solved job against a string vector of PackageIDs to ensure any
  * packages that match the PackageIDs match them fully.
@@ -44,54 +43,42 @@
     guint count, bool reject_non_updates)
 {
 	bool		success;
-	gchar	     ***id_splits;
+	struct query_id *query_ids;
 
 	assert(jobs != NULL);
 	assert(package_ids != NULL);
 	assert(0 < count);
 
 	success = false;
-	id_splits = NULL;
 
-	/* Split all the IDs first so we don't have to do it multiple times */
-	id_splits = make_package_id_splits(package_ids, count);
-	if (id_splits != NULL) {
+	query_ids = query_id_array_from_package_ids(package_ids, count);
+	if (query_ids != NULL) {
 
 		/* Now do the actual checking, per package. */
-		success = jobs_check_split_package_ids(jobs, id_splits, count,
+		success = jobs_check_query_ids(jobs, query_ids, count,
 		    reject_non_updates);
-
-		free_package_id_splits(&id_splits, count);
 	}
 
 	return success;
 }
 
 static bool
-jobs_check_id_on_package(struct pkg *pkg, gchar **split_id,
-    const char *name, const char *version)
+jobs_check_id_on_package(struct pkg *pkg, struct query_id *query_id,
+    const char *namever)
 {
 	bool		success;
-	gchar	       *match_id;
 
 	assert(pkg != NULL);
-	assert(split_id != NULL);
-	assert(name != NULL);
-	assert(version != NULL);
+	assert(query_id != NULL);
+	assert(query_id->namever != NULL);
+	assert(namever != NULL);
 
 	success = true;
 
 	/* Does this package's name and version match a PackageID? */
-	if ((strcmp(name, split_id[PK_PACKAGE_ID_NAME]) == 0) &&
-	    (strcmp(version, split_id[PK_PACKAGE_ID_VERSION]) == 0)) {
+	if (strcmp(namever, query_id->namever) == 0) {
 		/* Does the rest of the PackageID match up? */
-		match_id = pkgutils_pkg_match_id(pkg, split_id);
-
-		if (match_id == NULL) {
-			success = false;
-		} else {
-			free(match_id);
-		}
+		success = query_match_pkg_to_id(pkg, query_id);
 	}
 
 	return success;
@@ -99,108 +86,58 @@
 
 
 static bool
-jobs_check_split_package_ids(struct pkg_jobs *jobs, gchar ***id_splits,
+jobs_check_query_ids(struct pkg_jobs *jobs, struct query_id *query_ids,
     guint count, bool reject_non_updates)
 {
 	bool		success;
 	guint		i;
 	int		err;
-	const char     *name;
-	const char     *version;
+	char	       *namever;
 	struct pkg     *pkg;
 
 	assert(jobs != NULL);
-	assert(id_splits != NULL);
+	assert(query_ids != NULL);
 	assert(0 < count);
 
 
 	pkg = NULL;
 	success = true;
- 	while (success) {
- 		err = pkg_jobs(jobs, &pkg);
- 		if (err != EPKG_OK) {
- 			/* Did we reach the end of the job iterator? */
- 			if (err != EPKG_END) {
- 				success = false;
- 			}
- 			break;	
- 		}
-
- 		assert(pkg != NULL);
-
- 		name = version = NULL;
- 		pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version);
-
- 		for (i = 0; i < count; i++) {
- 			if (!success) {
- 				/* Leave the for loop, not the while loop. */
- 				break;
- 			}
-
- 			assert(success);
- 			success = jobs_check_id_on_package(pkg, id_splits[i],
- 			    name, version);
-
- 			if (success && reject_non_updates &&
- 			    pkgutils_pkg_install_state(pkg) !=
- 			    PK_INFO_ENUM_UPDATING) {
- 				success = false;
-	 		}
- 		}
-
- 		/* Do not free the struct pkg, we actually don't own it. */
- 	}
-
- 	return success;
-}
-
-static gchar ***
-make_package_id_splits(gchar **package_ids, guint count)
-{
-	guint		i;
-	gchar	     ***id_splits;
+	while (success) {
+		err = pkg_jobs(jobs, &pkg);
+		if (err != EPKG_OK) {
+			/* Did we reach the end of the job iterator? */
+			if (err != EPKG_END) {
+				success = false;
+			}
+			break;
+		}
 
-	id_splits = calloc(count, sizeof(gchar **));
+		assert(pkg != NULL);
 
-	if (id_splits != NULL) {
-		bool		split_success;
+		namever = pkgutils_pkg_namever(pkg);
+		if (namever == NULL) {
+			success = false;
+		}
 
-		split_success = true;
 		for (i = 0; i < count; i++) {
-			id_splits[i] = pk_package_id_split(package_ids[i]);
-			if (id_splits[i] == NULL) {
-				split_success = false;
+			if (!success) {
+				/* Leave the for loop, not the while loop. */
 				break;
 			}
-		}
-
-		if (!split_success) {
-			free_package_id_splits(&id_splits, count);
-		}
-
-		/* split_success if and only if id_splits != NULL */
-		assert(split_success || id_splits == NULL);
-		assert(!split_success || id_splits != NULL);
-	}
-
-	return id_splits;
-}
 
-static void
-free_package_id_splits(gchar ****id_splits_p, guint count)
-{
-	guint		i;
-
-	assert(id_splits_p != NULL);
-
-	if (*id_splits_p != NULL) {
-		for (i = 0; i < count; i++) {
-			g_strfreev((*id_splits_p)[i]);
+			assert(success);
+			success = jobs_check_id_on_package(pkg, query_ids + i,
+			    namever);
+
+			if (success && reject_non_updates &&
+			    pkgutils_pkg_install_state(pkg) !=
+			    PK_INFO_ENUM_UPDATING) {
+				success = false;
+			}
 		}
 
-		free(*id_splits_p);
-		*id_splits_p = NULL;
+		/* Do not free the struct pkg, we actually don't own it. */
 	}
 
-	assert(*id_splits_p == NULL);
+	return success;
 }

Modified: soc2013/mattbw/backend/pkgutils.c
==============================================================================
--- soc2013/mattbw/backend/pkgutils.c	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/pkgutils.c	Sun Aug 25 16:24:36 2013	(r256539)
@@ -174,111 +174,18 @@
 }
 
 /*
- * Compares a package to a split PackageID; returns the package's canonical
- * PackageID if they match and NULL otherwise.
- */
-gchar *
-pkgutils_pkg_match_id(struct pkg *pkg, gchar **split_id)
-{
-	bool		success;
-	int		i;
-	gchar          *match_id;
-	const char    **pkg_id_bits;
-
-	assert(pkg != NULL);
-	assert(split_id != NULL);
-	assert(g_strv_length(split_id) == 4);
-
-	success = false;
-	match_id = NULL;
-
-	pkg_id_bits = calloc(4, sizeof(const char *));
-	if (pkg_id_bits != NULL) {
-		match_id = pkgutils_pkg_to_id_through(pkg, pkg_id_bits);
-	}
-
-	if (match_id != NULL) {
-		bool		match_failed;
-
-		assert(pkg_id_bits != NULL);
-
-		/*
-		 * Succeed if this package's PackageID fields match the
-		 * original PackageID.  Of course, the original ID might have
-		 * missing fields (NULLs), so we treat a comparison involving
-		 * one as a success. This means using our "weak strcmp"
-		 * instead of normal strcmp or even g_strcmp0.
-		 */
-		match_failed = false;
-		for (i = PK_PACKAGE_ID_NAME; i <= PK_PACKAGE_ID_DATA; i++) {
-		    	if (!string_match(split_id[i], pkg_id_bits[i])) {
-				match_failed = true;
-				break;
-			}
-		}
-
-		if (match_failed) {
-			g_free(match_id);
-			match_id = NULL;
-		} else {
-			success = true;
-		}
-
-	}
-
-	free(pkg_id_bits);
-
-	assert (success || match_id == NULL);
-	assert (!success || match_id != NULL);
-
-	/* The strings inside this are owned by 'pkg'. Don't free them */
-
-	return match_id;
-}
-
-/*
  * Converts a package to a PackageID.
  */
 gchar          *
 pkgutils_pkg_to_id(struct pkg *pkg)
 {
-	gchar          *id;
-	const char    **id_bits;
-
-	/* Make sure the initial string vector's pointers are all NULL */
-	id_bits = calloc(4, sizeof(const char *));
-
-	/*
-	 * This is split through an intermediate function so the same code
-	 * can be used for the ID-checking logic.
-	 */
-	id = pkgutils_pkg_to_id_through(pkg, id_bits);
-
-	/* we don't own any of the strings, so we don't free those. */
-	free(id_bits);
-
-	return id;
-}
-
-/*
- * Converts a package to a PackageID, dumping the intermediate information
- * into the pointed-to string vector (which must have at least 4 places, and
- * they should be NULL).
- */
-gchar          *
-pkgutils_pkg_to_id_through(struct pkg *pkg, const char **strv)
-{
-
-	assert(pkg != NULL);
-	assert(strv != NULL);
+	gchar	       *strv[4];
 
 	pkg_get(pkg,
 	    PKG_NAME, strv + PK_PACKAGE_ID_NAME,
 	    PKG_VERSION, strv + PK_PACKAGE_ID_VERSION,
 	    PKG_ARCH, strv + PK_PACKAGE_ID_ARCH);
 
-	strv[PK_PACKAGE_ID_DATA] = pkgutils_pk_repo_of(pkg);
-
 	return pk_package_id_build(strv[PK_PACKAGE_ID_NAME],
 	    strv[PK_PACKAGE_ID_VERSION],
 	    strv[PK_PACKAGE_ID_ARCH],

Modified: soc2013/mattbw/backend/pkgutils.h
==============================================================================
--- soc2013/mattbw/backend/pkgutils.h	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/pkgutils.h	Sun Aug 25 16:24:36 2013	(r256539)
@@ -31,9 +31,7 @@
 char	       *pkgutils_package_id_namever(gchar *package_id);
 char	       *pkgutils_pkg_namever(struct pkg *pkg);
 const char     *pkgutils_pk_repo_of(struct pkg *pkg);
-gchar	       *pkgutils_pkg_match_id(struct pkg *pkg, gchar **split_id);
 gchar          *pkgutils_pkg_to_id(struct pkg *pkg);
-gchar          *pkgutils_pkg_to_id_through(struct pkg *pkg, const gchar **strv);
 void		pkgutils_add_old_version(struct pkgdb *db, struct pkg *pkg, struct pkg **old_p);
 void		pkgutils_emit(struct pkg *pkg, PkBackend *backend, PkInfoEnum info);
 void		pkgutils_emit_filtered(struct pkg *pkg, PkBackend *backend, PkBitfield filters, PkInfoEnum info);

Modified: soc2013/mattbw/backend/query.h
==============================================================================
--- soc2013/mattbw/backend/query.h	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/query.h	Sun Aug 25 16:24:36 2013	(r256539)
@@ -23,6 +23,7 @@
 
 /* Meta-header for the public interfaces to the query system. */
 
+#include "query/depends.h"	/* query_depends_... */
 #include "query/do.h"		/* query_do_... */
 #include "query/match.h"	/* query_match_... */
 #include "query/id.h"		/* query_id_... */

Modified: soc2013/mattbw/backend/query/core.h
==============================================================================
--- soc2013/mattbw/backend/query/core.h	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/query/core.h	Sun Aug 25 16:24:36 2013	(r256539)
@@ -27,7 +27,6 @@
 
 struct query;
 
-typedef		bool   (*emit_ptr) (struct pkg *pkg, const gchar *id, struct query *q);
 typedef		bool   (*query_body_ptr) (struct query *q);
 
 /*

Modified: soc2013/mattbw/backend/query/depends.c
==============================================================================
--- soc2013/mattbw/backend/query/depends.c	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/query/depends.c	Sun Aug 25 16:24:36 2013	(r256539)
@@ -23,31 +23,103 @@
 #include "pkg.h"		/* pkg... */
 #include "../pk-backend.h"	/* PkBackend */
 
-#include "depends.h"		/* query_depends_... */
+#include "../pkgutils.h"	/* pkgutils_... */
 #include "../utils.h"		/* ERR */
+#include "depends.h"		/* query_depends_... */
+#include "id.h"			/* query_id, query_id_... */
+#include "match.h"		/* query_match_... */
+
+static struct pkg *id_to_package(gchar *package_id, struct pkgdb *db, unsigned int load_flags);
+static gchar *dep_to_package_id(struct pkg_dep *dep);
 
 bool
-query_depends_emit(PkBackend *backend, struct pkg *pkg, depends_get_ptr get)
+query_depends_emit(PkBackend *backend, struct pkg *pkg, depends_get_ptr get,
+    struct pkgdb *db, unsigned int load_flags)
 {
 	bool		success;
-	gchar	       *package_id;
 	struct pkg_dep *dep;
 
 	assert(backend != NULL);
 	assert(pkg != NULL);
 	assert(get != NULL);
 
-	success = false;
+	success = true;
 
 	dep = NULL;
 	while (get(pkg, &dep) == EPKG_OK) {
+		gchar	       *package_id;
+		struct pkg     *package;
+
+
 		package_id = dep_to_package_id(dep);
-		assert(package_id != NULL);
+
+		/*
+		 * Does this dependency correspond to a package in our
+		 * database?
+		 */
+
+		package = id_to_package(package_id, db, load_flags);
+		if (package == NULL) {
+			pkgutils_emit(pkg, backend,
+			    pkgutils_pkg_current_state(pkg));
+			success = true;
+		} else {
+			success = (pk_backend_package(backend,
+			    PK_INFO_ENUM_UNKNOWN,
+			    package_id,
+			    "Could not find this package."));
+		}
 
 		g_free(package_id);
-	}
 
-	ERR(backend, PK_ERROR_ENUM_NOT_SUPPORTED, "soon");
+		if (!success) {
+			break;
+		}
+	}
 
 	return success;
 }
+
+/* Attempts to match a dependency to a package. */
+static struct pkg *
+id_to_package(gchar *package_id, struct pkgdb *db, unsigned int load_flags)
+{
+	struct pkg     *package;
+	struct query_id query_id;
+
+	assert(package_id != NULL);
+	assert(db != NULL);
+
+	package = NULL;
+
+	if (package_id != NULL) {
+		bool success;
+
+		success = query_id_from_package_id(package_id, &query_id);
+		if (success) {
+			package = query_match_id(&query_id, db, load_flags);
+		}
+	}
+
+	return package;
+}
+
+/*
+ * Converts a pkg_dep into a (partial) package ID.
+ *
+ * The result may be NULL and should be freed using g_free.
+ */
+static gchar *
+dep_to_package_id(struct pkg_dep *dep)
+{
+	const char     *name;
+	const char     *version;
+
+	assert(dep != NULL);
+
+	name = pkg_dep_get(dep, PKG_DEP_NAME);
+	version = pkg_dep_get(dep, PKG_DEP_VERSION);
+
+	return pk_package_id_build(name, version, "", "");
+}
+

Modified: soc2013/mattbw/backend/query/depends.h
==============================================================================
--- soc2013/mattbw/backend/query/depends.h	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/query/depends.h	Sun Aug 25 16:24:36 2013	(r256539)
@@ -27,7 +27,7 @@
 
 typedef		int   (*depends_get_ptr) (const struct pkg *pkg, struct pkg_dep **dep);
 
-bool		query_depends_emit(PkBackend *backend, struct pkg *pkg, depends_get_ptr get);
+bool		query_depends_emit(PkBackend *backend, struct pkg *pkg, depends_get_ptr get, struct pkgdb *db, unsigned int load_flags);
 
 #endif				/*_PKGNG_BACKEND_QUERY_DEPENDS_H_*/
 

Modified: soc2013/mattbw/backend/query/do.c
==============================================================================
--- soc2013/mattbw/backend/query/do.c	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/query/do.c	Sun Aug 25 16:24:36 2013	(r256539)
@@ -18,24 +18,24 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-/*
- * Mid-level functions for performing queries. For more high-level wrappers
- * for these, see match.[ch].
- */
+/* High-level functions for performing queries. */
 
+#include <assert.h>		/* assert */
+#include <stdbool.h>		/* bool, true, false */
 #include "pkg.h"		/* pkg_... */
 #include "../pk-backend.h"	/* pk_... */
 
 #include "../db.h"		/* db_... */
-
+#include "../utils.h"		/* get_strv_and_length */
 #include "do.h"			/* query_do_... */
-#include "core.h"		/* query_... */
+#include "match.h"		/* query_match_... */
+#include "packages.h"		/* query_packages_... */
 
-typedef struct query_id (*query_id_func_ptr) (gchar **strings, guint count);
+typedef struct query_id * (*query_id_func_ptr) (gchar **strings, guint count);
 
-static bool emit_packages(PkBackend *backend, struct pkgdb *db, emit_ptr emitter, struct pkg *packages, unsigned int count);
-static bool query_do_from_backend_ids(PkBackend *backend, unsigned int load_flags, emit_ptr emitter, query_id_func_ptr to_query_ids)
-static bool query_with_db(struct pkgdb *db, PkBackend *backend, unsigned int load_flags, emit_ptr emitter);
+static bool emit_packages(PkBackend *backend, struct pkgdb *db, emit_ptr emitter, struct pkg **packages, unsigned int count);
+static bool query_do_from_backend(PkBackend *backend, unsigned int load_flags, emit_ptr emitter, query_id_func_ptr to_query_ids);
+static bool query_with_db(struct pkgdb *db, PkBackend *backend, unsigned int load_flags, emit_ptr emitter, query_id_func_ptr to_query_ids);
 
 /*
  * Runs a query over the PackageIDs selected in the backend that sends the
@@ -75,7 +75,7 @@
 }
 
 static bool
-query_do_from_backend_ids(PkBackend *backend, unsigned int load_flags,
+query_do_from_backend(PkBackend *backend, unsigned int load_flags,
     emit_ptr emitter, query_id_func_ptr to_query_ids)
 {
 	bool		success;
@@ -98,13 +98,13 @@
 
 static bool
 query_with_db(struct pkgdb *db, PkBackend *backend, unsigned int load_flags,
-    emit_ptr emitter)
+    emit_ptr emitter, query_id_func_ptr to_query_ids)
 {
 	bool		success;
 	guint		count;
 	struct pkg    **packages;
 	struct query_id *query_ids;
-	gchar	      **package_ids;
+	gchar         **package_ids;
 
 	assert(backend != NULL);
 	assert(db != NULL);
@@ -113,26 +113,27 @@
 	success = false;
 	packages = NULL;
 
-	package_ids = pk_backend_get_strv("package_ids");
+	package_ids = get_strv_and_length(backend, "package_ids", &count);
 	assert(package_ids != NULL);
-	count = g_strv_length(package_ids);
 
-	query_ids = query_id_array_from_package_ids(package_ids, count);
+	query_ids = to_query_ids(package_ids, count);
 	if (query_ids != NULL) {
 		packages = query_match_ids(query_ids, count, db, load_flags);
 	}
 
 	if (packages != NULL) {
 		success = emit_packages(backend, db, emitter, packages, count);
-		query_free_packages(packages, count);
+		query_packages_array_free(&packages, count);
 	}
 
+	query_id_array_free(&query_ids, count);
+
 	return success;
 }
 
 static bool
 emit_packages(PkBackend *backend, struct pkgdb *db, emit_ptr emitter,
-    struct pkg *packages, unsigned int count)
+    struct pkg **packages, unsigned int count)
 {
 	bool		success;
 	unsigned int	i;
@@ -144,8 +145,8 @@
 
 	success = true;
 	for (i = 0; i < count; i++) {
-		success = emitter(backend, db, packages + i);
-		if (success = false) {
+		success = emitter(backend, db, packages[i]);
+		if (success == false) {
 			break;
 		}
 	}

Modified: soc2013/mattbw/backend/query/find.c
==============================================================================
--- soc2013/mattbw/backend/query/find.c	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/query/find.c	Sun Aug 25 16:24:36 2013	(r256539)
@@ -0,0 +1,89 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at FreeBSD.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/* Functions for finding a package given its query ID. */
+
+#include <assert.h>		/* assert */
+#include <stdbool.h>
+#include "pkg.h"
+
+#include "../utils.h"		/* INTENTIONALLY_IGNORE */
+#include "find.h"		/* query_find_... */
+#include "id.h"			/* struct query_id */
+
+static bool can_remote_iterate(struct query_id *query_id, unsigned int load_flags);
+
+struct pkgdb_it *
+query_find_local(struct query_id *query_id, struct pkgdb *db,
+    unsigned int load_flags)
+{
+
+	assert(query_id != NULL);
+	assert(db != NULL);
+	INTENTIONALLY_IGNORE(load_flags);
+	return pkgdb_query(db, query_id->namever, MATCH_EXACT);
+}
+
+struct pkgdb_it *
+query_find_remote(struct query_id *query_id, struct pkgdb *db,
+    unsigned int load_flags)
+{
+	struct pkgdb_it *iterator;
+
+	assert(query_id != NULL);
+	assert(db != NULL);
+	iterator = pkgdb_rquery(db, query_id->namever, MATCH_EXACT,
+	    query_id->repo);
+
+	/*
+	 * Make sure we can use this iterator.  (We only check now so that
+	 * the case of there being no remote matches is properly handled.)
+	 */
+	if (!(iterator == NULL || can_remote_iterate(query_id, load_flags))) {
+		pkgdb_it_free(iterator);
+		iterator = NULL;
+	}
+
+	return iterator;
+}
+
+/*
+ * Checks to see if trying to do a remote package iteration with this query
+ * could spell disaster.
+ */
+static bool
+can_remote_iterate(struct query_id *query_id, unsigned int load_flags)
+{
+	bool		sane;
+
+	assert(query_id != NULL);
+
+	/* Innocent until proven guilty */
+	sane = true;
+
+	/*
+	 * Stop pkg from catching fire if we try to load files from
+	 * non-installed packages.
+	 */
+	if (load_flags & PKG_LOAD_FILES) {
+		sane = false;
+	}
+	return sane;
+}

Modified: soc2013/mattbw/backend/query/id.c
==============================================================================
--- soc2013/mattbw/backend/query/id.c	Sun Aug 25 15:38:16 2013	(r256538)
+++ soc2013/mattbw/backend/query/id.c	Sun Aug 25 16:24:36 2013	(r256539)
@@ -31,13 +31,12 @@
 static char    *join_namever(const char *name, const char *version);

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-soc-all mailing list