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

mattbw at FreeBSD.org mattbw at FreeBSD.org
Sat Jul 13 11:19:22 UTC 2013


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

Log:
  implemented barebones version of remove_packages; simulation seems to be broken

Modified:
  soc2013/mattbw/backend/Makefile
  soc2013/mattbw/backend/actions.h
  soc2013/mattbw/backend/actions/install_packages.c
  soc2013/mattbw/backend/actions/remove_packages.c
  soc2013/mattbw/backend/pk-backend-pkgng.c
  soc2013/mattbw/backend/pkgutils.c
  soc2013/mattbw/backend/pkgutils.h
  soc2013/mattbw/backend/query/core.c

Modified: soc2013/mattbw/backend/Makefile
==============================================================================
--- soc2013/mattbw/backend/Makefile	Sat Jul 13 10:47:17 2013	(r254750)
+++ soc2013/mattbw/backend/Makefile	Sat Jul 13 11:19:21 2013	(r254751)
@@ -18,6 +18,7 @@
 		actions/get_repo_list.c		\
 		actions/install_files.c		\
 		actions/install_packages.c	\
+		actions/remove_packages.c	\
 		actions/resolve.c		\
 		actions/search_groups.c		\
 		actions/search_names.c
@@ -38,7 +39,7 @@
 .if USE_PK_PKGCONF
 PKGS+=		packagekit-glib2
 .else
-CFLAGS+=	-isystem/usr/local/include/PackageKit -isystem/usr/local/include/PackageKit/backend
+CFLAGS+=	-I/usr/local/include/PackageKit -I/usr/local/include/PackageKit/backend
 LDFLAGS+=	-L/usr/local/lib -lpackagekit-glib2
 .endif
 

Modified: soc2013/mattbw/backend/actions.h
==============================================================================
--- soc2013/mattbw/backend/actions.h	Sat Jul 13 10:47:17 2013	(r254750)
+++ soc2013/mattbw/backend/actions.h	Sat Jul 13 11:19:21 2013	(r254751)
@@ -34,9 +34,11 @@
 gboolean	install_files_thread(PkBackend *backend);
 gboolean	install_packages_thread(PkBackend *backend);
 gboolean	resolve_thread(PkBackend *backend);
+gboolean	remove_packages_thread(PkBackend *backend);
 gboolean	search_groups_thread(PkBackend *backend);
 gboolean	search_names_thread(PkBackend *backend);
 gboolean	simulate_install_files_thread(PkBackend *backend);
 gboolean	simulate_install_packages_thread(PkBackend *backend);
+gboolean	simulate_remove_packages_thread(PkBackend *backend);
 
 #endif				/* !_PKGNG_BACKEND_ACTIONS_H_ */

Modified: soc2013/mattbw/backend/actions/install_packages.c
==============================================================================
--- soc2013/mattbw/backend/actions/install_packages.c	Sat Jul 13 10:47:17 2013	(r254750)
+++ soc2013/mattbw/backend/actions/install_packages.c	Sat Jul 13 11:19:21 2013	(r254751)
@@ -24,12 +24,10 @@
 #include "pkg.h"		/* pkg... */
 
 #include "../actions.h"		/* install_packages_thread prototype */
-#include "../event.h"		/* event_... */
 #include "../pkgutils.h"	/* pkgutils_... */
 #include "../query.h"		/* query_... */
-#include "../utils.h"		/* INTENTIONALLY_IGNORE, ERR */
 
-static bool	job (struct pkg_jobs *jobs, struct query *q);
+static bool	job(struct pkg_jobs *jobs, struct query *q);
 static bool	sim_job(struct pkg_jobs *jobs, struct query *q);
 
 /*

Modified: soc2013/mattbw/backend/actions/remove_packages.c
==============================================================================
--- soc2013/mattbw/backend/actions/remove_packages.c	Sat Jul 13 10:47:17 2013	(r254750)
+++ soc2013/mattbw/backend/actions/remove_packages.c	Sat Jul 13 11:19:21 2013	(r254751)
@@ -24,14 +24,11 @@
 #include "pkg.h"		/* pkg... */
 
 #include "../actions.h"		/* remove_packages_thread prototype */
-#include "../event.c"		/* event_... */
 #include "../pkgutils.h"	/* pkgutils_... */
 #include "../query.h"		/* query_... */
-#include "../utils.h"		/* INTENTIONALLY_IGNORE, ERR */
 
 static bool	job (struct pkg_jobs *jobs, struct query *q);
 static bool	sim_job(struct pkg_jobs *jobs, struct query *q);
-static bool	solve_job(struct query *q, struct pkg_jobs *jobs);
 
 /*
  * The thread that performs an removePackages operation. Should be invoked
@@ -43,14 +40,14 @@
 	bool		success;
 
 	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
-	success = query_match_id_to_job(backend, PKG_JOBS_remove, job);
+	success = query_match_id_to_job(backend, PKG_JOBS_DEINSTALL, job);
 
 	(void)pk_backend_finished(backend);
 	return success ? TRUE : FALSE;
 }
 
 /*
- * The thread that performs a Simulate removePackages operation. Should be
+ * The thread that performs a Simulate RemovePackages operation. Should be
  * invoked by the pk_backend_simulate_remove_packages hook.
  */
 gboolean
@@ -59,7 +56,7 @@
 	bool		success;
 
 	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
-	success = query_match_id_to_job(backend, PKG_JOBS_remove, sim_job);
+	success = query_match_id_to_job(backend, PKG_JOBS_DEINSTALL, sim_job);
 
 	(void)pk_backend_finished(backend);
 	return success ? TRUE : FALSE;
@@ -71,31 +68,12 @@
 static bool
 job(struct pkg_jobs *jobs, struct query *q)
 {
-	bool		success;
-	PkBackend      *backend;
 
-	success = false;
-	backend = query_backend(q);
-	query_set_percentage(q, 0);
-
-	pkg_event_register(event_cb, backend);
-
-	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_REMOVE);
-	if (pkg_jobs_count(jobs) == 0)
-		ERR(backend,
-		    PK_RROR_ENUM_PACKAGE_NOT_INSTALLED,
-		    "nothing to do");
-	else if (pkg_jobs_apply(jobs) != EPKG_OK)
-		ERR(backend,
-		    PK_ERROR_ENUM_PACKAGE_FAILED_TO_REMOVE,
-		    "job failed");
-	else
-	success = true;
-
-cleanup:
-	pkg_event_register(NULL, NULL);
-	query_set_percentage(q, 100);
-	return success;
+	return query_jobs_apply_emitter(jobs,
+	    q,
+	    PK_STATUS_ENUM_REMOVE,
+	    PK_ERROR_ENUM_PACKAGE_NOT_INSTALLED,
+	    PK_ERROR_ENUM_PACKAGE_FAILED_TO_REMOVE);
 }
 
 /*
@@ -104,54 +82,8 @@
 static bool
 sim_job(struct pkg_jobs *jobs, struct query *q)
 {
-	bool		success;
-	PkBackend      *backend;
-	struct pkg     *pkg;
-
-	backend = query_backend(q);
-	success = false;
-	query_set_percentage(q, 0);
-
-	if (solve_job(q, jobs) == false)
-		goto cleanup;
-
-	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_RUNNING);
-	pkg = NULL;
-	while (pkg_jobs(jobs, &pkg) == EPKG_OK)
-		pkgutils_emit(pkg,
-		    backend,
-		    pkgutils_pkg_remove_state(pkg));
-
-	success = true;
-
-cleanup:
-	query_set_percentage(q, 100);
-	return success;
-}
-
-/*
- * Solves a job and ensures it has packages available.
- */
-static bool
-solve_job(struct query *q, struct pkg_jobs *jobs)
-{
-	bool		success;
-	PkBackend      *backend;
-
-	success = false;
-	backend = query_backend(q);
-
-	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_DEP_RESOLVE);
-	if (pkg_jobs_solve(jobs) != EPKG_OK)
-		ERR(backend,
-		    PK_ERROR_ENUM_DEP_RESOLUTION_FAILED,
-		    "could not solve the job");
-	else if (pkg_jobs_count(jobs) == 0)
-		ERR(backend,
-		    PK_ERROR_ENUM_INTERNAL_ERROR,
-		    "job contains no packages");
-	else
-		success = true;
 
-	return success;
+	return query_jobs_simulate_emitter(jobs,
+	    q,
+	    pkgutils_pkg_remove_state);
 }

Modified: soc2013/mattbw/backend/pk-backend-pkgng.c
==============================================================================
--- soc2013/mattbw/backend/pk-backend-pkgng.c	Sat Jul 13 10:47:17 2013	(r254750)
+++ soc2013/mattbw/backend/pk-backend-pkgng.c	Sat Jul 13 11:19:21 2013	(r254751)
@@ -27,10 +27,12 @@
 #include "pk-backend.h"
 #include "pkg.h"
 
-#include "utils.h"		/* INTENTIONALLY_IGNORE */
+#include "utils.h"		/* INTENTIONALLY_IGNORE, ERR */
 #include "group.h"		/* group_bitfield */
 #include "actions.h"		/* Actions threads */
 
+#define	THREAD(bend, thread)	(void)pk_backend_thread_create((bend), (thread))
+
 void
 pk_backend_initialize(PkBackend *backend)
 {
@@ -41,9 +43,7 @@
 	if (!pkg_initialized())
 		err = pkg_init(NULL);
 	if (err)
-		(void)pk_backend_error_code(backend,
-		    PK_ERROR_ENUM_INTERNAL_ERROR,
-		    "could not initialise pkg");
+		ERR(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "couldn't init pkg");
 }
 
 void
@@ -90,7 +90,7 @@
 {
 
 	INTENTIONALLY_IGNORE(package_ids);	/* retrieved from backend */
-	(void)pk_backend_thread_create(backend, get_details_thread);
+	THREAD(backend, get_details_thread);
 }
 
 void
@@ -98,7 +98,7 @@
 {
 
 	INTENTIONALLY_IGNORE(package_ids);	/* retrieved from backend */
-	(void)pk_backend_thread_create(backend, get_files_thread);
+	THREAD(backend, get_files_thread);
 }
 
 PkBitfield
@@ -142,7 +142,7 @@
 {
 
 	INTENTIONALLY_IGNORE(filters);	/* not yet supported */
-	(void)pk_backend_thread_create(backend, get_repo_list_thread);
+	THREAD(backend, get_repo_list_thread);
 }
 
 void
@@ -152,7 +152,7 @@
 
 	INTENTIONALLY_IGNORE(only_trusted);	/* not yet supported */
 	INTENTIONALLY_IGNORE(full_paths);	/* retrieved from backend */
-	(void)pk_backend_thread_create(backend, install_files_thread);
+	THREAD(backend, install_files_thread);
 }
 
 void
@@ -162,34 +162,45 @@
 
 	INTENTIONALLY_IGNORE(only_trusted);	/* not yet supported */
 	INTENTIONALLY_IGNORE(package_ids);	/* retrieved from backend */
-	(void)pk_backend_thread_create(backend, install_packages_thread);
+	THREAD(backend, install_packages_thread);
+}
+
+void
+pk_backend_remove_packages(PkBackend *backend, gchar **package_ids,
+    gboolean allow_deps, gboolean autoremove)
+{
+
+	INTENTIONALLY_IGNORE(package_ids);	/* retrieved from backend */
+	INTENTIONALLY_IGNORE(allow_deps);	/* not yet supported */
+	INTENTIONALLY_IGNORE(autoremove);	/* not yet supported */
+	THREAD(backend, remove_packages_thread);
 }
 
 void
 pk_backend_resolve(PkBackend *backend, PkBitfield filters, gchar **package_ids)
 {
 
-	INTENTIONALLY_IGNORE(filters);	/* retrieved from backend */
+	INTENTIONALLY_IGNORE(filters);		/* retrieved from backend */
 	INTENTIONALLY_IGNORE(package_ids);	/* retrieved from backend */
-	(void)pk_backend_thread_create(backend, resolve_thread);
+	THREAD(backend, resolve_thread);
 }
 
 void
 pk_backend_search_groups(PkBackend *backend, PkBitfield filters, gchar **values)
 {
 
-	INTENTIONALLY_IGNORE(filters);	/* retrieved from backend */
+	INTENTIONALLY_IGNORE(filters);		/* retrieved from backend */
 	(void)pk_backend_set_strv(backend, "values", values);
-	(void)pk_backend_thread_create(backend, search_groups_thread);
+	THREAD(backend, search_groups_thread);
 }
 
 void
 pk_backend_search_names(PkBackend *backend, PkBitfield filters, gchar **values)
 {
 
-	INTENTIONALLY_IGNORE(filters);	/* retrieved from backend */
+	INTENTIONALLY_IGNORE(filters);		/* retrieved from backend */
 	(void)pk_backend_set_strv(backend, "values", values);
-	(void)pk_backend_thread_create(backend, search_names_thread);
+	THREAD(backend, search_names_thread);
 }
 
 void
@@ -197,7 +208,7 @@
 {
 
 	INTENTIONALLY_IGNORE(full_paths);	/* retrieved from backend */
-	(void)pk_backend_thread_create(backend, simulate_install_files_thread);
+	THREAD(backend, simulate_install_files_thread);
 }
 
 void
@@ -205,6 +216,15 @@
 {
 
 	INTENTIONALLY_IGNORE(package_ids);	/* retrieved from backend */
-	(void)pk_backend_thread_create(backend,
-	    simulate_install_packages_thread);
+	THREAD(backend, simulate_install_packages_thread);
+}
+
+void
+pk_backend_simulate_remove_packages(PkBackend *backend, gchar **package_ids,
+    gboolean autoremove)
+{
+
+	INTENTIONALLY_IGNORE(package_ids);	/* retrieved from backend */
+	INTENTIONALLY_IGNORE(autoremove);	/* not yet supported */
+	THREAD(backend, simulate_remove_packages_thread);
 }

Modified: soc2013/mattbw/backend/pkgutils.c
==============================================================================
--- soc2013/mattbw/backend/pkgutils.c	Sat Jul 13 10:47:17 2013	(r254750)
+++ soc2013/mattbw/backend/pkgutils.c	Sat Jul 13 11:19:21 2013	(r254751)
@@ -25,6 +25,7 @@
 #include "pkg.h"
 
 #include "pkgutils.h"		/* Prototypes */
+#include "utils.h"		/* INTENTIONALLY_IGNORE */
 
 static const char *repo_of_remote(struct pkg *pkg);
 
@@ -84,6 +85,18 @@
 }
 
 /*
+ * Infers the correct PkInfoEnum to emit for this package if it is being
+ * removed.
+ */
+PkInfoEnum
+pkgutils_pkg_remove_state(struct pkg *pkg)
+{
+
+	INTENTIONALLY_IGNORE(pkg);
+	return PK_INFO_ENUM_REMOVING;
+}
+
+/*
  * Gets the PackageKit repository name for the package.
  */
 const char     *

Modified: soc2013/mattbw/backend/pkgutils.h
==============================================================================
--- soc2013/mattbw/backend/pkgutils.h	Sat Jul 13 10:47:17 2013	(r254750)
+++ soc2013/mattbw/backend/pkgutils.h	Sat Jul 13 11:19:21 2013	(r254751)
@@ -27,6 +27,7 @@
 
 PkInfoEnum	pkgutils_pkg_current_state(struct pkg *pkg);
 PkInfoEnum	pkgutils_pkg_install_state(struct pkg *pkg);
+PkInfoEnum	pkgutils_pkg_remove_state(struct pkg *pkg);
 const char     *pkgutils_pk_repo_of(struct pkg *pkg);
 gchar          *pkgutils_pkg_to_id(struct pkg *pkg);
 gchar          *pkgutils_pkg_to_id_through(struct pkg *pkg, const gchar **strv);

Modified: soc2013/mattbw/backend/query/core.c
==============================================================================
--- soc2013/mattbw/backend/query/core.c	Sat Jul 13 10:47:17 2013	(r254750)
+++ soc2013/mattbw/backend/query/core.c	Sat Jul 13 11:19:21 2013	(r254751)
@@ -144,17 +144,16 @@
 }
 
 /*
- * Retrieves the repository for the query, or NULL if none is specified.
+ * Retrieves the repository for the query, or NULL if none is specified (or
+ * the query is using the local database only).
  */
 const char *
 query_repo(struct query *q)
 {
-	const gchar    *repo;
-
 	assert(q != NULL);
 
-	repo = q->id_strv[PK_PACKAGE_ID_DATA];
-	return ((repo == NULL || repo[0] == '\0') ? NULL : repo);
+	return (q->rtype == REPO_REMOTE ?
+	    q->id_strv[PK_PACKAGE_ID_DATA] : NULL);
 }
  
 /*


More information about the svn-soc-all mailing list