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

mattbw at FreeBSD.org mattbw at FreeBSD.org
Sat Jul 27 20:11:11 UTC 2013


Author: mattbw
Date: Sat Jul 27 20:11:10 2013
New Revision: 255231
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255231

Log:
  Move jobs and do more work on UpdateSystem.
  
  Applying and emitting jobs is now part of the jobs.h file, with the query
  functions merely wrapping this in PackageKit status updates.  This is in
  preparation for UpdateSystem which does not need to use query, and possibly
  for the rest of the jobs-based actions if a way of doing jobs without them
  arises.
  
  UpdateSystem needs to be renamed at the C source level to upgrade_system
  before PackageKit will find it (weird!) so this remains unfinished and
  untested.
  

Modified:
  soc2013/mattbw/backend/actions/update_system.c
  soc2013/mattbw/backend/jobs.c
  soc2013/mattbw/backend/jobs.h
  soc2013/mattbw/backend/query/jobs.c

Modified: soc2013/mattbw/backend/actions/update_system.c
==============================================================================
--- soc2013/mattbw/backend/actions/update_system.c	Sat Jul 27 19:57:20 2013	(r255230)
+++ soc2013/mattbw/backend/actions/update_system.c	Sat Jul 27 20:11:10 2013	(r255231)
@@ -24,77 +24,72 @@
 #include "../pk-backend.h"	/* pk..., Pk... */
 #include "pkg.h"		/* pkg... */
 
-#include "../actions.h"		/* update_packages_thread prototype */
+#include "../actions.h"		/* update_system_thread prototype */
 #include "../pkgutils.h"	/* pkgutils_... */
-#include "../query.h"		/* query_... */
+#include "../jobs.h"		/* jobs_... */
 
-static bool	job(struct pkg_jobs *jobs, struct query *q);
-static bool	sim_job(struct pkg_jobs *jobs, struct query *q);
+static gboolean	update_system(PkBackend *backend, bool simulate);
 
 /*
- * The thread that performs an UpdatePackages operation. Should be invoked
- * by the pk_backend_update_packages hook.
+ * The thread that performs an UpdateSystem operation. Should be invoked
+ * by the pk_backend_update_system hook.
  */
 gboolean
-update_packages_thread(PkBackend *backend)
+update_system_thread(PkBackend *backend)
 {
-	bool		success;
 
-	assert(backend != NULL);
+	return update_system(backend, false);
+}
 
-	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
-	success = query_match_id_to_job(backend, PKG_JOBS_INSTALL, job);
+gboolean
+simulate_update_system_thread(PkBackend *backend)
+{
 
-	(void)pk_backend_finished(backend);
-	return success ? TRUE : FALSE;
+	return update_system(backend, true);
 }
 
-/*
- * The thread that performs a SimulateUpdatePackages operation. Should be
- * invoked by the pk_backend_simulate_update_packages hook.
- */
-gboolean
-simulate_update_packages_thread(PkBackend *backend)
+static gboolean
+update_system(PkBackend *backend, bool simulate)
 {
 	bool		success;
+	struct pkgdb   *db;
+	struct pkg_jobs *jobs;
 
 	assert(backend != NULL);
 
-	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
-	success = query_match_id_to_job(backend, PKG_JOBS_UPGRADE, sim_job);
+	db = db_open_remote(backend);
+	if (db == NULL)
+		goto cleanup;
+
+	/* UpdateSystem is a job with no packages, so there's no need to use
+	 * the full query approach.
+	 */
+	jobs = NULL;
+	if (pkg_jobs_new(&jobs, type, db) != EPKG_OK) {
+		ERR(backend,
+		    PK_ERROR_ENUM_INTERNAL_ERROR,
+		    "could not init pkg_jobs");
+		goto cleanup;
+	}
+	if (pkg_jobs_solve(jobs) != EPKG_OK) {
+		ERR(backend,
+		    PK_ERROR_ENUM_DEP_RESOLUTION_FAILED,
+		    "could not solve the job");
+		goto cleanup;
+	}	
+
+	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_UPDATE);
+
+	if (simulate) {
+		success = true;
+		jobs_emit_packages(jobs, backend,
+		    pkgutils_pkg_install_state);
+	} else
+		success = jobs_apply(jobs, backend,
+		    PK_ERROR_ENUM_NO_PACKAGES_TO_UPDATE,
+		    PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL);
 
+cleanup:
 	(void)pk_backend_finished(backend);
 	return success ? TRUE : FALSE;
 }
-
-/*
- * Tries to process the given solved installation jobs.
- */
-static bool
-job(struct pkg_jobs *jobs, struct query *q)
-{
-
-	assert(jobs != NULL);
-	assert(q != NULL);
-
-	return query_jobs_apply_emitter(jobs,
-	    q,
-	    PK_STATUS_ENUM_UPDATE,
-	    PK_ERROR_ENUM_NO_PACKAGES_TO_UPDATE,
-	    PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL);
-}
-
-/*
- * Tries to simulate processing the given installation jobs.
- */
-static bool
-sim_job(struct pkg_jobs *jobs, struct query *q)
-{
-
-	assert(jobs != NULL);
-	assert(q != NULL);
-
-	return query_jobs_simulate_emitter(jobs,
-	    q,
-	    pkgutils_pkg_install_state);
-}

Modified: soc2013/mattbw/backend/jobs.c
==============================================================================
--- soc2013/mattbw/backend/jobs.c	Sat Jul 27 19:57:20 2013	(r255230)
+++ soc2013/mattbw/backend/jobs.c	Sat Jul 27 20:11:10 2013	(r255231)
@@ -21,9 +21,12 @@
 /* Helpers for jobs that don't rely on the query system. */
 
 #include <assert.h>		/* assert */
+#include <stdbool.h>		/* bool, true, false */
 #include "pk-backend.h"		/* pk_..., Pk... */
 #include "pkg.h"		/* pkg_... */
 
+#include "event.h"		/* event_cb */
+#include "utils.h"		/* ERR */
 #include "pkgutils.h"		/* pkgutils_... */
 #include "jobs.h"		/* jobs_... */
 
@@ -44,3 +47,27 @@
  		pkgutils_emit(pkg, backend, info(pkg));
  	}
 }
+
+/* Applies a job with the given error enums and the standard event callback. */
+bool
+jobs_apply(struct pkg_jobs *jobs, PkBackend *backend,
+    PkErrorEnum no_jobs, PkErrorEnum job_failed)
+{
+	bool success;
+
+	success = false;
+	assert(backend != NULL);
+
+	pkg_event_register(event_cb, backend);
+
+	if (pkg_jobs_count(jobs) == 0)
+		ERR(backend, no_jobs, "nothing to do");
+	else if (pkg_jobs_apply(jobs) != EPKG_OK)
+		ERR(backend, job_failed, "job failed");
+	else
+		success = true;
+
+	pkg_event_register(NULL, NULL);
+
+	return success;
+}

Modified: soc2013/mattbw/backend/jobs.h
==============================================================================
--- soc2013/mattbw/backend/jobs.h	Sat Jul 27 19:57:20 2013	(r255230)
+++ soc2013/mattbw/backend/jobs.h	Sat Jul 27 20:11:10 2013	(r255231)
@@ -21,11 +21,12 @@
 #ifndef _PKGNG_BACKEND_JOBS_H_
 #define _PKGNG_BACKEND_JOBS_H_
 
-#include <glib.h>		/* gboolean */
+#include <stdbool.h>		/* bool */
 #include "pk-backend.h"		/* PkBackend */
 
 typedef		PkInfoEnum (*pkg_info_ptr) (struct pkg *pkg);
 
 void	jobs_emit_packages(struct pkg_jobs *jobs, PkBackend *backend, pkg_info_ptr info);
+bool	jobs_apply(struct pkg_jobs *jobs, PkBackend *backend, PkErrorEnum no_jobs, PkErrorEnum job_failed);
 
 #endif				/* !_PKGNG_BACKEND_JOBS_H_ */

Modified: soc2013/mattbw/backend/query/jobs.c
==============================================================================
--- soc2013/mattbw/backend/query/jobs.c	Sat Jul 27 19:57:20 2013	(r255230)
+++ soc2013/mattbw/backend/query/jobs.c	Sat Jul 27 20:11:10 2013	(r255231)
@@ -46,25 +46,14 @@
 	assert(jobs != NULL);
 	assert(q != NULL);
 
-	success = false;
-
 	backend = query_backend(q);
-	assert(backend != NULL);
-
-	query_set_percentage(q, 0);
-
-	pkg_event_register(event_cb, backend);
 
-	(void)pk_backend_set_status(backend, status);
-	if (pkg_jobs_count(jobs) == 0)
-		ERR(backend, no_jobs, "nothing to do");
-	else if (pkg_jobs_apply(jobs) != EPKG_OK)
-		ERR(backend, job_failed, "job failed");
-	else
-		success = true;
+	STATUS(backend, status);
 
-	pkg_event_register(NULL, NULL);
+	query_set_percentage(q, 0);
+	success = jobs_apply(jobs, backend, no_jobs, job_failed);
 	query_set_percentage(q, 100);
+
 	return success;
 }
 


More information about the svn-soc-all mailing list