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

mattbw at FreeBSD.org mattbw at FreeBSD.org
Tue Jul 9 07:29:26 UTC 2013


Author: mattbw
Date: Tue Jul  9 07:29:25 2013
New Revision: 254454
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254454

Log:
  more cleanup mainly to allow -Weverything -Wno-system-includes to work

Modified:
  soc2013/mattbw/backend/.indent.pro
  soc2013/mattbw/backend/Makefile
  soc2013/mattbw/backend/actions/get_details.c
  soc2013/mattbw/backend/actions/install_packages.c
  soc2013/mattbw/backend/groups.c
  soc2013/mattbw/backend/groups.h
  soc2013/mattbw/backend/licenses.c
  soc2013/mattbw/backend/pkgutils.c
  soc2013/mattbw/backend/query/core.c
  soc2013/mattbw/backend/query/do.c
  soc2013/mattbw/backend/utils.h

Modified: soc2013/mattbw/backend/.indent.pro
==============================================================================
--- soc2013/mattbw/backend/.indent.pro	Tue Jul  9 07:17:29 2013	(r254453)
+++ soc2013/mattbw/backend/.indent.pro	Tue Jul  9 07:29:25 2013	(r254454)
@@ -1,3 +1,5 @@
+-TPkBitfield
+-TPkGroupEnum
 -TPkBackend
 -Tgchar
 -Tgboolean

Modified: soc2013/mattbw/backend/Makefile
==============================================================================
--- soc2013/mattbw/backend/Makefile	Tue Jul  9 07:17:29 2013	(r254453)
+++ soc2013/mattbw/backend/Makefile	Tue Jul  9 07:29:25 2013	(r254454)
@@ -33,13 +33,19 @@
 .if USE_PK_PKGCONF
 PKGS+=		packagekit-glib2
 .else
-CFLAGS+=	-I/usr/local/include/PackageKit -I/usr/local/include/PackageKit/backend
+CFLAGS+=	-isystem/usr/local/include/PackageKit -isystem/usr/local/include/PackageKit/backend
 LDFLAGS+=	-L/usr/local/lib -lpackagekit-glib2
 .endif
 
 CFLAGS+=	`pkg-config --cflags ${PKGS}`
 CFLAGS+=	-DPK_COMPILATION
 LDFLAGS+=	`pkg-config --libs ${PKGS}`
-CSTD?=		c99
+CSTD?=		c11
+
+# NOTE: remove this before finishing
+CFLAGS+=	--pedantic -Weverything -Werror -Wno-system-headers	\
+		-isystem /usr/local/include/glib-2.0			\
+		-isystem /usr/local/include				\
+		-isystem /usr/include
 
 .include <bsd.lib.mk>

Modified: soc2013/mattbw/backend/actions/get_details.c
==============================================================================
--- soc2013/mattbw/backend/actions/get_details.c	Tue Jul  9 07:17:29 2013	(r254453)
+++ soc2013/mattbw/backend/actions/get_details.c	Tue Jul  9 07:29:25 2013	(r254454)
@@ -20,6 +20,7 @@
 
 #include <glib.h>
 #include <stdbool.h>
+#include <stdint.h>
 #include "../pk-backend.h"
 #include "pkg.h"
 
@@ -57,6 +58,7 @@
 	const char     *origin;
 	const char     *www;
 	int64_t		flatsize;
+	guint		flatsize_u;
 
 	query_set_percentage(q, 0);
 
@@ -69,13 +71,15 @@
 	    PKG_ORIGIN, &origin,
 	    PKG_WWW, &www);
 
+	flatsize_u = (guint)CLAMP(flatsize, 0, G_MAXUINT);
+
 	success = pk_backend_details(query_backend(q),
 	    id,
 	    license_name_from_pkg(pkg),
 	    group_from_origin(origin),
 	    description,
 	    www,
-	    flatsize) == TRUE;
+	    flatsize_u) == TRUE;
 
 	query_set_percentage(q, 100);
 	return success;

Modified: soc2013/mattbw/backend/actions/install_packages.c
==============================================================================
--- soc2013/mattbw/backend/actions/install_packages.c	Tue Jul  9 07:17:29 2013	(r254453)
+++ soc2013/mattbw/backend/actions/install_packages.c	Tue Jul  9 07:29:25 2013	(r254454)
@@ -68,7 +68,7 @@
 /*
  * Tries to process the given solved installation jobs.
  */
-static		bool
+static bool
 job(struct pkg_jobs *jobs, struct query *q)
 {
 	bool		success;
@@ -101,7 +101,7 @@
 /*
  * Tries to simulate processing the given installation jobs.
  */
-static		bool
+static bool
 sim_job(struct pkg_jobs *jobs, struct query *q)
 {
 	bool		success;
@@ -132,7 +132,7 @@
 /*
  * Solves a job and ensures it has packages available.
  */
-static		bool
+static bool
 solve_job(struct query *q, struct pkg_jobs *jobs)
 {
 	bool		success;
@@ -157,7 +157,8 @@
 }
 
 /*
- * Event handler for events emitted by pkg during an installation.
+ * Event handler for events emitted by pkg during an installation. TODO: Many
+ * of these events are unhandled or deficiently handled.
  */
 static int
 install_event_cb(void *backend_v, struct pkg_event *event)
@@ -166,9 +167,9 @@
 
 	backend = (PkBackend *)backend_v;
 
-	/* TODO: percentage bar */
 	switch (event->type) {
 	case PKG_EVENT_INSTALL_BEGIN:
+		STATUS(backend, PK_STATUS_ENUM_INSTALL);
 		pkgutils_emit(event->e_install_begin.pkg,
 		    backend,
 		    PK_INFO_ENUM_INSTALLING);
@@ -179,6 +180,7 @@
 		    PK_INFO_ENUM_FINISHED);
 		break;
 	case PKG_EVENT_DEINSTALL_BEGIN:
+		STATUS(backend, PK_STATUS_ENUM_REMOVE);
 		pkgutils_emit(event->e_deinstall_begin.pkg,
 		    backend,
 		    PK_INFO_ENUM_REMOVING);
@@ -189,6 +191,7 @@
 		    PK_INFO_ENUM_FINISHED);
 		break;
 	case PKG_EVENT_UPGRADE_BEGIN:
+		STATUS(backend, PK_STATUS_ENUM_UPDATE);
 		pkgutils_emit(event->e_upgrade_begin.pkg,
 		    backend,
 		    PK_INFO_ENUM_UPDATING);
@@ -198,29 +201,56 @@
 		    backend,
 		    PK_INFO_ENUM_FINISHED);
 		break;
+	case PKG_EVENT_FETCHING:
+		STATUS(backend, PK_STATUS_ENUM_DOWNLOAD);
+		break;
+	case PKG_EVENT_INTEGRITYCHECK_BEGIN:
+	case PKG_EVENT_INTEGRITYCHECK_FINISHED:
+		/* Unimplemented */
+		break;
+	case PKG_EVENT_INTEGRITYCHECK_CONFLICT:
+		ERR(backend,
+		    PK_ERROR_ENUM_PACKAGE_CORRUPT,
+		    event->e_integrity_conflict.pkg_name);
+		break;
+	case PKG_EVENT_NEWPKGVERSION:
+	case PKG_EVENT_NOTICE:
+	case PKG_EVENT_INCREMENTAL_UPDATE:
+		/* Unimplemented */
+		break;
 	case PKG_EVENT_ERROR:
 		/*
 		 * This is sometimes used for nonfatal errors, so we can't
-		 * throw an error code here
+		 * throw an error code here.
 		 */
-#if 0
-		ERR(backend,
-		    PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL,
-		    event->e_pkg_error.msg);
-#endif
+		break;
+	case PKG_EVENT_ERRNO:
+	case PKG_EVENT_ARCHIVE_COMP_UNSUP:
+	case PKG_EVENT_ALREADY_INSTALLED:
+	case PKG_EVENT_FAILED_CKSUM:
+	case PKG_EVENT_CREATE_DB_ERROR:
+	case PKG_EVENT_LOCKED:
+	case PKG_EVENT_REQUIRED:
+	case PKG_EVENT_MISSING_DEP:
+	case PKG_EVENT_NOREMOTEDB:
+	case PKG_EVENT_NOLOCALDB:
+		/* Unimplemented */
 		break;
 	case PKG_EVENT_FILE_MISMATCH:
 		ERR(backend,
 		    PK_ERROR_ENUM_PACKAGE_CORRUPT,
 		    pkg_file_path(event->e_file_mismatch.file));
 		break;
+	case PKG_EVENT_DEVELOPER_MODE:
+	case PKG_EVENT_PLUGIN_ERRNO:
+	case PKG_EVENT_PLUGIN_ERROR:
+	case PKG_EVENT_PLUGIN_INFO:
+		/* Unimplemented */
+		break;
 	case PKG_EVENT_NOT_FOUND:
 		ERR(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/groups.c
==============================================================================
--- soc2013/mattbw/backend/groups.c	Tue Jul  9 07:17:29 2013	(r254453)
+++ soc2013/mattbw/backend/groups.c	Tue Jul  9 07:29:25 2013	(r254454)
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include <assert.h>		/* assert */
 #include <stdlib.h>		/* NULL */
 #include <string.h>		/* strchr, strdup */
 
@@ -25,12 +26,11 @@
 #include "pk-backend.h"		/* PkGroupEnum, PK_* */
 
 #include "groups.h"		/* prototypes */
-#include "mappings.h"		/* mapping macros */
 
-static const char	ORIGIN_SEPARATOR = '/';
+static const char ORIGIN_SEPARATOR = '/';
 
 struct group_mapping {
-	const char /* @null@ */ *key;
+	const char     *key;
 	PkGroupEnum	group;
 };
 
@@ -112,9 +112,11 @@
 	{"x11-toolkits", PK_GROUP_ENUM_DESKTOP_OTHER},
 	{"x11-wm", PK_GROUP_ENUM_DESKTOP_OTHER},
 	/* Default (for new/unspecified ports directories) */
-	{NULL, PK_GROUP_ENUM_UNKNOWN}
+	{"", PK_GROUP_ENUM_UNKNOWN}
 };
 
+static PkGroupEnum group_from_port_dir(const char *port_dir);
+
 /* Reports the PackageKit groups available on this backend as a bitfield. */
 PkBitfield
 available_groups(void)
@@ -123,30 +125,23 @@
 	PkBitfield	bits;
 
 	bits = 0;
-	for (i = 0; group_mappings[i].key != NULL; i++)
+	for (i = 0; group_mappings[i].key[0] != '\0'; i++)
 		pk_bitfield_add(bits, group_mappings[i].group);
 
 	return bits;
 }
 
-/* Maps from port/origin directories to PackageKit groups. */
-PkGroupEnum
-group_from_port_dir( /* @null@ */ const char *port_dir)
-{
-	struct group_mapping *result;
-
-	MAPPING_FIND(port_dir, &result, group_mappings);
-	return result->group;
-}
-
 /* Maps from package origins to PackageKit groups. */
 PkGroupEnum
 group_from_origin(const char *origin)
 {
+	size_t		len;
 	char           *dir;
 	char           *sep;
 	PkGroupEnum	group;
 
+	assert(origin != NULL);
+
 	/* Find the separation between dir and port name */
 	sep = strchr(origin, ORIGIN_SEPARATOR);
 
@@ -156,10 +151,25 @@
 	 * origin start and the separator mark the port directory name we
 	 * want to use.
 	 */
-	dir = (sep == NULL ? NULL : strndup(origin, sep - origin));
+	len = (size_t) (sep == NULL ? 0 : sep - origin);
+	dir = strndup(origin, len);
 	group = group_from_port_dir(dir);
-	if (dir)
-		free(dir);
+	free(dir);
 
 	return group;
 }
+
+/* Maps from port/origin directories to PackageKit groups. */
+static PkGroupEnum
+group_from_port_dir(const char *port_dir)
+{
+	struct group_mapping *result;
+
+	assert(port_dir != NULL);
+
+	for (result = group_mappings;
+	    result->key[0] != '\0' && strcmp(result->key, port_dir) != 0;
+	    result++);
+
+	return result->group;
+}

Modified: soc2013/mattbw/backend/groups.h
==============================================================================
--- soc2013/mattbw/backend/groups.h	Tue Jul  9 07:17:29 2013	(r254453)
+++ soc2013/mattbw/backend/groups.h	Tue Jul  9 07:29:25 2013	(r254454)
@@ -25,6 +25,5 @@
 
 PkBitfield	available_groups(void);
 PkGroupEnum	group_from_origin(const char *origin);
-PkGroupEnum	group_from_port_dir(const char *port_dir);
 
 #endif				/* _PKGNG_BACKEND_GROUPS_H_ */

Modified: soc2013/mattbw/backend/licenses.c
==============================================================================
--- soc2013/mattbw/backend/licenses.c	Tue Jul  9 07:17:29 2013	(r254453)
+++ soc2013/mattbw/backend/licenses.c	Tue Jul  9 07:29:25 2013	(r254454)
@@ -50,7 +50,7 @@
 	case LICENSE_AND:
 		logic_str = " and ";
 		break;
-	default:
+	case LICENSE_SINGLE:
 		logic_str = " ";
 		break;
 	}

Modified: soc2013/mattbw/backend/pkgutils.c
==============================================================================
--- soc2013/mattbw/backend/pkgutils.c	Tue Jul  9 07:17:29 2013	(r254453)
+++ soc2013/mattbw/backend/pkgutils.c	Tue Jul  9 07:29:25 2013	(r254454)
@@ -67,9 +67,6 @@
 		case PKG_UPGRADE:
 			info = PK_INFO_ENUM_UPDATING;
 			break;
-		default:
-			/* Stick with the above default. */
-			break;
 		}
 	}
 	return info;
@@ -84,6 +81,7 @@
 	const char     *repo;
 
 	switch (pkg_type(pkg)) {
+	case PKG_OLD_FILE:
 	case PKG_FILE:
 		repo = "local";
 		break;
@@ -93,7 +91,7 @@
 	case PKG_REMOTE:
 		repo = repo_of_remote(pkg);
 		break;
-	default:
+	case PKG_NONE:
 		repo = "unknown";
 		break;
 	}

Modified: soc2013/mattbw/backend/query/core.c
==============================================================================
--- soc2013/mattbw/backend/query/core.c	Tue Jul  9 07:17:29 2013	(r254453)
+++ soc2013/mattbw/backend/query/core.c	Tue Jul  9 07:29:25 2013	(r254454)
@@ -68,7 +68,7 @@
 	bool		success;
 	bool		try_local;
 	bool		try_remote;
-	int		match;
+	match_t		match;
 	PkBitfield	filters;
 	const char     *name;
 	const char     *repo;

Modified: soc2013/mattbw/backend/query/do.c
==============================================================================
--- soc2013/mattbw/backend/query/do.c	Tue Jul  9 07:17:29 2013	(r254453)
+++ soc2013/mattbw/backend/query/do.c	Tue Jul  9 07:29:25 2013	(r254454)
@@ -56,9 +56,6 @@
 		case QUERY_SINGLE_ID:
 			success = do_single(backend, db, s, t);
 			break;
-		default:
-			success = false;
-			break;
 		}
 
 		pkgdb_close(db);

Modified: soc2013/mattbw/backend/utils.h
==============================================================================
--- soc2013/mattbw/backend/utils.h	Tue Jul  9 07:17:29 2013	(r254453)
+++ soc2013/mattbw/backend/utils.h	Tue Jul  9 07:29:25 2013	(r254454)
@@ -24,8 +24,10 @@
 #include <stdbool.h>		/* bool */
 
 #define	INTENTIONALLY_IGNORE(x)	(void)(x)
+#define STATUS(backend, status) \
+	(void)pk_backend_set_status((backend), (status))
 #define	ERR(backend, type, msg) \
-	(void) pk_backend_error_code((backend), (type), (msg))
+	(void)pk_backend_error_code((backend), (type), (msg))
 
 bool		string_match(const char *left, const char *right);
 


More information about the svn-soc-all mailing list