socsvn commit: r254258 - in soc2013/mattbw/backend: . actions

mattbw at FreeBSD.org mattbw at FreeBSD.org
Sat Jul 6 21:11:01 UTC 2013


Author: mattbw
Date: Sat Jul  6 21:11:01 2013
New Revision: 254258
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254258

Log:
  some cleanup and splinting

Modified:
  soc2013/mattbw/backend/actions/get-details.c
  soc2013/mattbw/backend/actions/get-files.c
  soc2013/mattbw/backend/actions/install-packages.c
  soc2013/mattbw/backend/db.c
  soc2013/mattbw/backend/query.c
  soc2013/mattbw/backend/query.h

Modified: soc2013/mattbw/backend/actions/get-details.c
==============================================================================
--- soc2013/mattbw/backend/actions/get-details.c	Sat Jul  6 20:39:44 2013	(r254257)
+++ soc2013/mattbw/backend/actions/get-details.c	Sat Jul  6 21:11:01 2013	(r254258)
@@ -28,9 +28,9 @@
 
 #include "actions.h"		/* get_details_thread prototype */
 
-static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_LICENSES;
+static const unsigned int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_LICENSES;
 
-static void	emit(struct pkg *pkg, const gchar *id, struct query *q);
+static gboolean	emit(struct pkg *pkg, const gchar *id, struct query *q);
 
 /*
  * The thread that performs a GetDetails operation. Should be invoked by the
@@ -39,13 +39,14 @@
 gboolean
 get_details_thread(PkBackend *backend)
 {
+
 	return query_match_id_to_emitter(backend, LOAD_FLAGS, emit);
 }
 
 /*
  * Emits the given package's details. To be used as an iterating function.
  */
-static void
+static gboolean
 emit(struct pkg *pkg, const gchar *id, struct query *q)
 {
 	const char     *description;
@@ -54,17 +55,19 @@
 	int64_t		flatsize;
 
 	/* Information not already part of the PackageID */
+	description = origin = www = NULL;
+	flatsize = 0;
 	pkg_get(pkg,
 		PKG_DESC, &description,
 		PKG_FLATSIZE, &flatsize,
 		PKG_ORIGIN, &origin,
 		PKG_WWW, &www);
 
-	pk_backend_details(query_backend(q),
-			   id,
-			   license_name_from_pkg(pkg),
-			   group_from_origin(origin),
-			   description,
-			   www,
-			   flatsize);
+	return pk_backend_details(query_backend(q),
+				  id,
+				  license_name_from_pkg(pkg),
+				  group_from_origin(origin),
+				  description,
+				  www,
+				  flatsize);
 }

Modified: soc2013/mattbw/backend/actions/get-files.c
==============================================================================
--- soc2013/mattbw/backend/actions/get-files.c	Sat Jul  6 20:39:44 2013	(r254257)
+++ soc2013/mattbw/backend/actions/get-files.c	Sat Jul  6 21:11:01 2013	(r254258)
@@ -32,9 +32,9 @@
 #include "actions.h"		/* get_files_thread prototype */
 
 static const int FILE_NAME_STEP = 10;
-static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_FILES;
+static const unsigned int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_FILES;
 
-static void	emit(struct pkg *pkg, const gchar *id, struct query *q);
+static gboolean	emit(struct pkg *pkg, const gchar *id, struct query *q);
 
 /*
  * The thread that performs a GetDetails operation. Should be invoked by the
@@ -50,14 +50,18 @@
 /*
  * Emits the given package's files. To be used as an iterating function.
  */
-static void
+static gboolean
 emit(struct pkg *pkg, const gchar *id, struct query *q)
 {
-	struct pkg_file *file;
+	gboolean	success;
 	int		err;
 	int		sb_err;
+	char           *filenames;
+	struct pkg_file *file;
 	struct sbuf    *sb;
 
+	success = FALSE;
+
 	/*
 	 * Construct a string of the form ";file1;file2;file3;...". We'll get
 	 * rid of the initial ; later.
@@ -65,20 +69,23 @@
 	sb = sbuf_new_auto();
 	for (HASH_FOR(err, pkg_files, pkg, &file))
 		sbuf_printf(sb, ";%s", pkg_file_path(file));
+
 	sb_err = sbuf_finish(sb);
-	if (sb_err)
+	if (sb_err) {
 		pk_backend_error_code(query_backend(q),
 				      PK_ERROR_ENUM_INTERNAL_ERROR,
 				      "couldn't construct filename string");
-	else {
-		char           *filenames;
+		goto cleanup;
+	}
 
-		filenames = sbuf_data(sb);
-		/* Skip over any initial ; */
-		if (filenames[0] == ';')
-			filenames++;
+	filenames = sbuf_data(sb);
+	/* Skip over any initial ; */
+	if (filenames[0] == ';')
+		filenames++;
 
-		pk_backend_files(query_backend(q), id, filenames);
-	}
+	success = pk_backend_files(query_backend(q), id, filenames);
+
+cleanup:
 	sbuf_delete(sb);
+	return success;
 }

Modified: soc2013/mattbw/backend/actions/install-packages.c
==============================================================================
--- soc2013/mattbw/backend/actions/install-packages.c	Sat Jul  6 20:39:44 2013	(r254257)
+++ soc2013/mattbw/backend/actions/install-packages.c	Sat Jul  6 21:11:01 2013	(r254258)
@@ -29,12 +29,12 @@
 
 #include "actions.h"		/* install_packages_thread prototype */
 
+static gboolean	do_install_packages(struct pkg_jobs *jobs, struct query *q, gboolean simulate);
+static gboolean	do_install_solved_job(struct pkg_jobs *jobs, PkBackend *backend, gboolean simulate);
+static gboolean	do_install_solved_job_real(struct pkg_jobs *jobs, PkBackend *backend);
+static gboolean	job (struct pkg_jobs *jobs, struct query *q);
+static gboolean	sim_job(struct pkg_jobs *jobs, struct query *q);
 static int	install_event_cb(void *backend_v, struct pkg_event *event);
-static void	do_install_packages(struct pkg_jobs *jobs, struct query *q, gboolean simulate);
-static void	do_install_solved_job(struct pkg_jobs *jobs, PkBackend *backend, gboolean simulate);
-static void	do_install_solved_job_real(struct pkg_jobs *jobs, PkBackend *backend);
-static void	job(struct pkg_jobs *jobs, struct query *q);
-static void	sim_job(struct pkg_jobs *jobs, struct query *q);
 
 
 /*
@@ -60,77 +60,15 @@
 }
 
 /*
- * Event handler for events emitted by pkg during an installation.
- */
-static int
-install_event_cb(void *backend_v, struct pkg_event *event)
-{
-	PkBackend *backend;
-
-	backend = (PkBackend *)backend_v;
-
-	/* TODO: percentage bar */
-	switch(event->type) {
-	case PKG_EVENT_INSTALL_BEGIN:
-		pkgutils_emit(event->e_install_begin.pkg,
-			      backend,
-			      PK_INFO_ENUM_INSTALLING);
-		break;
-	case PKG_EVENT_INSTALL_FINISHED:
-		pkgutils_emit(event->e_install_finished.pkg,
-			      backend,
-			      PK_INFO_ENUM_FINISHED);
-		break;
-	case PKG_EVENT_DEINSTALL_BEGIN:
-		pkgutils_emit(event->e_deinstall_begin.pkg,
-			      backend,
-			      PK_INFO_ENUM_REMOVING);
-		break;
-	case PKG_EVENT_DEINSTALL_FINISHED:
-		pkgutils_emit(event->e_deinstall_finished.pkg,
-			      backend,
-			      PK_INFO_ENUM_FINISHED);
-		break;
-	case PKG_EVENT_UPGRADE_BEGIN:
-		pkgutils_emit(event->e_upgrade_begin.pkg,
-			      backend,
-			      PK_INFO_ENUM_UPDATING);
-		break;
-	case PKG_EVENT_UPGRADE_FINISHED:
-		pkgutils_emit(event->e_upgrade_finished.pkg,
-			      backend,
-			      PK_INFO_ENUM_FINISHED);
-		break;
-	case PKG_EVENT_ERROR:
-		pk_backend_error_code(backend,
-				      PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL,
-				      event->e_pkg_error.msg);
-		break;
-	case PKG_EVENT_FILE_MISMATCH:
-		pk_backend_error_code(backend,
-				      PK_ERROR_ENUM_PACKAGE_CORRUPT,
-				      pkg_file_path(event->e_file_mismatch.file));
-		break;
-	case PKG_EVENT_NOT_FOUND:
-		pk_backend_error_code(backend,
-				      PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED,
-				      event->e_not_found.pkg_name);
-	default:
-		/* Do nothing for unrecognised events */
-		break;
-	}
-
-	return EPKG_OK;
-}
-
-/*
  * Installs (or pretends to install) an unsolved installation job.
  */
-static void
+static gboolean
 do_install_packages(struct pkg_jobs *jobs, struct query *q, gboolean simulate)
 {
+	gboolean	success;
 	PkBackend      *backend;
 
+	success = FALSE;
 	backend = query_backend(q);
 
 	pk_backend_set_status(backend, PK_STATUS_ENUM_DEP_RESOLVE);
@@ -143,19 +81,23 @@
 				      PK_ERROR_ENUM_INTERNAL_ERROR,
 				      "job contains no packages");
 	else
-		do_install_solved_job(jobs, backend, simulate);
+		success = do_install_solved_job(jobs, backend, simulate);
+
+	return success;
 }
 
 /*
  * Installs (or pretends to install) a fully solved installation job.
  */
-static void
+static gboolean
 do_install_solved_job(struct pkg_jobs *jobs,
 		      PkBackend *backend,
 		      gboolean simulate)
 {
+	gboolean	success;
 	struct pkg     *pkg;
 
+	success = TRUE;
 	pkg = NULL;
 	while (pkg_jobs(jobs, &pkg) == EPKG_OK)
 		pkgutils_emit(pkg,
@@ -163,43 +105,118 @@
 			      pkgutils_pkg_install_state(pkg));
 
 	if (simulate == FALSE)
-		do_install_solved_job_real(jobs, backend);
+		success = do_install_solved_job_real(jobs, backend);
+
+	return success;
 }
 
 /*
  * Actually installs a fully solved installation job.
  */
-static void
+static gboolean
 do_install_solved_job_real(struct pkg_jobs *jobs, PkBackend *backend)
 {
-	
+	gboolean	success;
+
+	success = FALSE;
+
 	pkg_event_register(install_event_cb, backend);
 
 	pk_backend_set_status(backend, PK_STATUS_ENUM_INSTALL);
-	if (pkg_jobs_apply(jobs) != EPKG_OK)
+	if (pkg_jobs_apply(jobs) == EPKG_OK)
+		success = TRUE;
+	else
 		pk_backend_error_code(backend,
-				      PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL,
+				    PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL,
 				      "job failed");
 
 	pkg_event_register(NULL, NULL);
+
+	return success;
 }
 
 /*
  * Tries to process the given solved installation jobs.
  */
-static void
+static gboolean
 job(struct pkg_jobs *jobs, struct query *q)
 {
 
-	do_install_packages(jobs, q, FALSE);
+	return do_install_packages(jobs, q, FALSE);
 }
 
 /*
  * Tries to simulate processing the given installation jobs.
  */
-static void
+static gboolean
 sim_job(struct pkg_jobs *jobs, struct query *q)
 {
 
-	do_install_packages(jobs, q, TRUE);
+	return do_install_packages(jobs, q, TRUE);
+}
+
+/*
+ * Event handler for events emitted by pkg during an installation.
+ */
+static int
+install_event_cb(void *backend_v, struct pkg_event *event)
+{
+	PkBackend      *backend;
+
+	backend = (PkBackend *)backend_v;
+
+	/* TODO: percentage bar */
+	switch (event->type) {
+	case PKG_EVENT_INSTALL_BEGIN:
+		pkgutils_emit(event->e_install_begin.pkg,
+			      backend,
+			      PK_INFO_ENUM_INSTALLING);
+		break;
+	case PKG_EVENT_INSTALL_FINISHED:
+		pkgutils_emit(event->e_install_finished.pkg,
+			      backend,
+			      PK_INFO_ENUM_FINISHED);
+		break;
+	case PKG_EVENT_DEINSTALL_BEGIN:
+		pkgutils_emit(event->e_deinstall_begin.pkg,
+			      backend,
+			      PK_INFO_ENUM_REMOVING);
+		break;
+	case PKG_EVENT_DEINSTALL_FINISHED:
+		pkgutils_emit(event->e_deinstall_finished.pkg,
+			      backend,
+			      PK_INFO_ENUM_FINISHED);
+		break;
+	case PKG_EVENT_UPGRADE_BEGIN:
+		pkgutils_emit(event->e_upgrade_begin.pkg,
+			      backend,
+			      PK_INFO_ENUM_UPDATING);
+		break;
+	case PKG_EVENT_UPGRADE_FINISHED:
+		pkgutils_emit(event->e_upgrade_finished.pkg,
+			      backend,
+			      PK_INFO_ENUM_FINISHED);
+		break;
+	case PKG_EVENT_ERROR:
+		pk_backend_error_code(backend,
+				    PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL,
+				      event->e_pkg_error.msg);
+		break;
+	case PKG_EVENT_FILE_MISMATCH:
+		pk_backend_error_code(backend,
+				      PK_ERROR_ENUM_PACKAGE_CORRUPT,
+				pkg_file_path(event->e_file_mismatch.file));
+		break;
+	case PKG_EVENT_NOT_FOUND:
+		pk_backend_error_code(backend,
+				      PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED,
+				      event->e_not_found.pkg_name);
+	default:
+		/* Do nothing for unrecognised events */
+		break;
+	}
+
+	return EPKG_OK;
 }
+
+

Modified: soc2013/mattbw/backend/db.c
==============================================================================
--- soc2013/mattbw/backend/db.c	Sat Jul  6 20:39:44 2013	(r254257)
+++ soc2013/mattbw/backend/db.c	Sat Jul  6 21:11:01 2013	(r254258)
@@ -27,6 +27,10 @@
 #include "db.h"			/* prototypes */
 #include "utils.h"		/* null_if_empty, split_id */
 
+static const unsigned int ACCESS_MODE = (unsigned int)(PKGDB_MODE_READ |
+						       PKGDB_MODE_WRITE);
+static const unsigned int ACCESS_DB = (unsigned int)(PKGDB_DB_LOCAL |
+						     PKGDB_DB_REPO);
 
 /*
  * Opens a pkgdb ready for remote operations. This will always return TRUE if
@@ -39,37 +43,35 @@
  * "pk_backend_initialize" and before "pk_backend_destroy".
  */
 gboolean
-open_remote_db(struct pkgdb **db, PkBackend *backend)
+open_remote_db(struct pkgdb **db_p, PkBackend *backend)
 {
 	gboolean	success;
-	int		access_return;
-	int		open_return;
 
 	success = FALSE;
 
-	pk_backend_set_status(backend, PK_STATUS_ENUM_WAITING_FOR_AUTH);
-	access_return = pkgdb_access(PKGDB_MODE_READ | PKGDB_MODE_WRITE,
-				     PKGDB_DB_LOCAL | PKGDB_DB_REPO);
-	if (access_return != EPKG_OK)
-		pk_backend_error_code(backend,
-				      PK_ERROR_ENUM_NOT_AUTHORIZED,
-				      "cannot access database");
-	else {
-		pk_backend_set_status(backend, PK_STATUS_ENUM_WAITING_FOR_LOCK);
-		open_return = pkgdb_open(db, PKGDB_REMOTE);
-		if (open_return != EPKG_OK)
-			pk_backend_error_code(backend,
-					      PK_ERROR_ENUM_CANNOT_GET_LOCK,
-					      "cannot open database");
-		else if (*db == NULL)
-			pk_backend_error_code(backend,
-					      PK_ERROR_ENUM_INTERNAL_ERROR,
+	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_WAITING_FOR_AUTH);
+	if (pkgdb_access(ACCESS_MODE, ACCESS_DB) != EPKG_OK) {
+		(void)pk_backend_error_code(backend,
+					    PK_ERROR_ENUM_NOT_AUTHORIZED,
+					    "cannot access database");
+		goto cleanup;
+	}
+	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_WAITING_FOR_LOCK);
+	if (pkgdb_open(db_p, PKGDB_REMOTE) != EPKG_OK) {
+		(void)pk_backend_error_code(backend,
+					    PK_ERROR_ENUM_CANNOT_GET_LOCK,
+					    "cannot open database");
+		goto cleanup;
+	}
+	if (*db_p == NULL) {
+		(void)pk_backend_error_code(backend,
+					    PK_ERROR_ENUM_INTERNAL_ERROR,
 				       "pkgdb_open gave us a null pointer");
-		else {
-			pk_backend_set_status(backend, PK_STATUS_ENUM_RUNNING);
-			success = TRUE;
-		}
+		goto cleanup;
 	}
+	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_RUNNING);
+	success = TRUE;
 
+cleanup:
 	return success;
 }

Modified: soc2013/mattbw/backend/query.c
==============================================================================
--- soc2013/mattbw/backend/query.c	Sat Jul  6 20:39:44 2013	(r254257)
+++ soc2013/mattbw/backend/query.c	Sat Jul  6 21:11:01 2013	(r254258)
@@ -51,17 +51,18 @@
 
 static gboolean	match(struct query *q, gchar **match_id_p, struct pkg **match_pkg_p);
 static gboolean	match_id_in_it(struct pkgdb_it *it, struct query *q, gchar **match_id_p, struct pkg **match_pkg_p);
+static gboolean	query_do(PkBackend *backend, unsigned int load_flags, emit_ptr emitter, pkg_jobs_t job_type, job_emit_ptr job_emitter, query_body_ptr body);
+static gboolean	query_emit_to_job(struct pkg *pkg, const gchar *id, struct query *q);
+static gboolean	query_match(struct query *q);
 static gboolean	try_id_match(struct pkg *pkg, struct query *q, gchar **match_id);
-static gboolean query_do(PkBackend *backend, int load_flags, emit_ptr emitter, pkg_jobs_t job_type, job_emit_ptr job_emitter, query_body_ptr body);
-static gboolean query_match(struct query *q);
 static int	jobs_add_pkg(struct pkg_jobs *jobs, match_t type, struct pkg *pkg);
-static void	query_emit_to_job(struct pkg *pkg, const gchar *id, struct query *q);
 static void	query_free_contents(struct query *q);
 
 /* Returns the backend stored inside the struct query. */
 PkBackend      *
 query_backend(struct query *q)
 {
+
 	return (q == NULL ? NULL : q->backend);
 }
 
@@ -70,7 +71,7 @@
 query_init(const gchar *id,
 	   PkBackend *backend,
 	   struct pkgdb *db,
-	   int load_flags,
+	   unsigned int load_flags,
 	   emit_ptr emitter,
 	   pkg_jobs_t job_type,
 	   job_emit_ptr job_emitter,
@@ -99,38 +100,42 @@
 			   &(q->version),
 			   &(q->arch),
 			   &(q->data));
-	if (success == FALSE)
+	if (success == FALSE) {
 		pk_backend_error_code(backend,
 				      PK_ERROR_ENUM_PACKAGE_ID_INVALID,
 				      "invalid package id");
+		goto cleanup;
+	}
 
 	/*
 	 * Check the repository to make sure it's sane, and populate the repo
 	 * type flags in the state for later consumption.
 	 */
-	if (success == TRUE) {
-		if (q->data == NULL)
-			q->any_repo = TRUE;
-		else if (strcmp(q->data, "installed") == 0)
-			q->local_repo = TRUE;
-		else if (pkg_repo_find_ident(q->data) == NULL) {
-			pk_backend_error_code(backend,
-					   PK_ERROR_ENUM_REPO_NOT_FOUND,
-					      "no such repository");
-			success = FALSE;
-		}
+	if (q->data == NULL)
+		q->any_repo = TRUE;
+	else if (strcmp(q->data, "installed") == 0)
+		q->local_repo = TRUE;
+	else if (pkg_repo_find_ident(q->data) == NULL) {
+		pk_backend_error_code(backend,
+				      PK_ERROR_ENUM_REPO_NOT_FOUND,
+				      "no such repository");
+		success = FALSE;
+		goto cleanup;
 	}
 	/*
 	 * Stop pkg from catching fire if we try to load files from
 	 * non-installed packages.
 	 */
 	loading_files = (load_flags & PKG_LOAD_FILES) ? TRUE : FALSE;
-	if (success == TRUE && q->local_repo == FALSE && loading_files) {
+	if (q->local_repo == FALSE && loading_files) {
 		pk_backend_error_code(backend,
 				      PK_ERROR_ENUM_CANNOT_GET_FILELIST,
 				      "cannot get files for remote package");
 		success = FALSE;
+		goto cleanup;
 	}
+
+cleanup:
 	if (success == FALSE) {
 		query_free(q);
 		q = NULL;
@@ -140,11 +145,11 @@
 }
 
 /*
- * Runs a query over the PackageIDs selected in the backend that sends the first
- * match to an emitting function.
+ * Runs a query over the PackageIDs selected in the backend that sends the
+ * first match to an emitting function.
  */
 gboolean
-query_match_id_to_emitter(PkBackend *backend, int load_flags, emit_ptr emitter)
+query_match_id_to_emitter(PkBackend *backend, unsigned int load_flags, emit_ptr emitter)
 {
 
 	return query_do(backend,
@@ -173,8 +178,8 @@
 }
 
 /*
- * Performs a package database query against a PackageID, and then emits
- * the first matching result.
+ * Performs a package database query against a PackageID, and then emits the
+ * first matching result.
  */
 static gboolean
 query_match(struct query *q)
@@ -205,11 +210,11 @@
  */
 static gboolean
 query_do(PkBackend *backend,
-         int load_flags,
-         emit_ptr emitter,
+	 unsigned int load_flags,
+	 emit_ptr emitter,
 	 pkg_jobs_t job_type,
-         job_emit_ptr job_emitter,
-         query_body_ptr body)
+	 job_emit_ptr job_emitter,
+	 query_body_ptr body)
 {
 	gboolean	no_error_yet;
 	gchar         **package_ids;
@@ -251,43 +256,60 @@
 /*
  * For adapting an emitter function into one that solves and applies a job.
  */
-static void
+static gboolean
 query_emit_to_job(struct pkg *pkg, const gchar *id, struct query *q)
 {
+	gboolean	success;
 	int		err;
 	struct pkg_jobs *jobs;
+	PkBackend      *backend;
 
 	INTENTIONALLY_IGNORE(id);
 
+	success = FALSE;
 	jobs = NULL;
+
+	if (q == NULL)
+		goto cleanup;
+
+	backend = query_backend(q);
+
 	err = pkg_jobs_new(&jobs, q->job_type, q->db);
-	if (err == EPKG_OK) {
-		if (q->data != NULL)
-			err = pkg_jobs_set_repository(jobs, q->data);
-		if (err == EPKG_OK) {
-			err = jobs_add_pkg(jobs, MATCH_EXACT, pkg);
-			if (err == EPKG_OK)
-				q->job_emitter(jobs, q);
-			else
-				pk_backend_error_code(q->backend,
-					       PK_ERROR_ENUM_INTERNAL_ERROR,
-						    "could not add to job");
-		} else
-			pk_backend_error_code(q->backend,
+	if (err != EPKG_OK) {
+		pk_backend_error_code(backend,
+				      PK_ERROR_ENUM_INTERNAL_ERROR,
+				      "could not init pkg_jobs");
+		goto cleanup;
+	}
+	if (q->data != NULL) {
+		err = pkg_jobs_set_repository(jobs, q->data);
+		if (err != EPKG_OK) {
+			pk_backend_error_code(backend,
 					      PK_ERROR_ENUM_REPO_NOT_FOUND,
 					      "could not set repo");
-	} else
-		pk_backend_error_code(q->backend,
+			goto cleanup;
+		}
+	}
+	err = jobs_add_pkg(jobs, MATCH_EXACT, pkg);
+	if (err != EPKG_OK) {
+		pk_backend_error_code(backend,
 				      PK_ERROR_ENUM_INTERNAL_ERROR,
-				      "could not init pkg_jobs");
+				      "could not add to job");
+		goto cleanup;
+	}
+
+	success = q->job_emitter(jobs, q);
 
+cleanup:
 	pkg_jobs_free(jobs);
+	return success;
 }
 
 /* Deallocates a struct query and any contents it owns. */
 void
 query_free(struct query *q)
 {
+
 	if (q != NULL) {
 		query_free_contents(q);
 		g_free(q);
@@ -306,11 +328,15 @@
 	gboolean	success;
 	gboolean	try_local;
 	gboolean	try_remote;
+	int		match;
+	const char     *name;
 	struct pkgdb   *db;
 	struct pkgdb_it *it;
 
 	success = FALSE;
+	match = MATCH_EXACT;
 	db = q->db;
+	name = q->name;
 
 	/*
 	 * If we're not given a specific repository in the PackageID, we want
@@ -325,19 +351,16 @@
 	}
 
 	/* Try a local search first, if applicable. */
-	if (try_local == TRUE)
-		it = pkgdb_query(db, q->name, MATCH_EXACT);
-	else
-		it = NULL;
+	it = (try_local ? pkgdb_query(db, name, match) : NULL);
 	if (it != NULL)
 		success = match_id_in_it(it, q, match_id_p, match_pkg_p);
 	pkgdb_it_free(it);
 
+	if (success == TRUE)
+		try_remote = FALSE;
+
 	/* Next, try a remote search, again only if applicable. */
-	if (success == FALSE && (try_remote == TRUE))
-		it = pkgdb_rquery(db, q->name, MATCH_EXACT, q->data);
-	else
-		it = NULL;
+	it = (try_remote ? pkgdb_rquery(db, name, match, q->data) : NULL);
 	if (it != NULL)
 		success = match_id_in_it(it, q, match_id_p, match_pkg_p);
 	pkgdb_it_free(it);
@@ -360,10 +383,11 @@
 	       gchar **match_id_p,
 	       struct pkg **match_pkg_p)
 {
-	/* TODO: Filters */
 	int		err;
 	int		load_flags;
 
+	/* TODO: Filters */
+
 	*match_pkg_p = NULL;
 	*match_id_p = NULL;
 	load_flags = q->load_flags;
@@ -390,8 +414,8 @@
 	/*
 	 * 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
+	 * (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.
 	 */
 	for (matches = TRUE, i = PK_PACKAGE_ID_NAME;
@@ -414,9 +438,11 @@
 	return pkg_jobs_add(jobs, type, &name, 1);
 }
 
+/* Frees the owned contents of a struct query, but not the struct itself. */
 static void
 query_free_contents(struct query *q)
 {
+
 	/* The database is owned by the creator and is not freed. */
 	/* This should free the other split ID pointer targets. */
 	if (q->strv != NULL)

Modified: soc2013/mattbw/backend/query.h
==============================================================================
--- soc2013/mattbw/backend/query.h	Sat Jul  6 20:39:44 2013	(r254257)
+++ soc2013/mattbw/backend/query.h	Sat Jul  6 21:11:01 2013	(r254258)
@@ -27,14 +27,14 @@
 
 struct query;
 
-typedef void    (*emit_ptr) (struct pkg *pkg, const gchar *id, struct query *q);
-typedef void    (*job_emit_ptr) (struct pkg_jobs *jobs, struct query *q);
+typedef gboolean (*emit_ptr) (struct pkg *pkg, const gchar *id, struct query *q);
+typedef gboolean (*job_emit_ptr) (struct pkg_jobs *jobs, struct query *q);
 typedef gboolean (*query_body_ptr) (struct query *q);
 
 PkBackend      *query_backend(struct query *q);
-gboolean	query_init(const gchar *id, PkBackend *backend, struct pkgdb *db, int load_flags, emit_ptr emitter, pkg_jobs_t job_type, job_emit_ptr job_emitter, struct query **q_p);
+gboolean	query_init(const gchar *id, PkBackend *backend, struct pkgdb *db, unsigned int load_flags, emit_ptr emitter, pkg_jobs_t job_type, job_emit_ptr job_emitter, struct query **q_p);
 
-gboolean	query_match_id_to_emitter(PkBackend *backend, int load_flags, emit_ptr emitter);
+gboolean	query_match_id_to_emitter(PkBackend *backend, unsigned int load_flags, emit_ptr emitter);
 gboolean	query_match_id_to_job(PkBackend *backend, pkg_jobs_t type, job_emit_ptr job_emitter);
 
 void		query_free(struct query *q);


More information about the svn-soc-all mailing list