Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Aug 2013 11:35:49 GMT
From:      mattbw@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r255638 - in soc2013/mattbw/backend: . jobs
Message-ID:  <201308071135.r77BZnXw042082@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mattbw
Date: Wed Aug  7 11:35:49 2013
New Revision: 255638
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255638

Log:
  Split checking functions off jobs.c.
  
  This moves a small chunk of code out of jobs.c, which is getting rather
  unmaintainably large.  It also allows further breaking down of the
  checking functions.
  
  This hasn't yet been tested aside from compilation, but should work unless
  I messed up the Makefile.
  

Added:
  soc2013/mattbw/backend/jobs/
  soc2013/mattbw/backend/jobs/check.c
  soc2013/mattbw/backend/jobs/check.h
Modified:
  soc2013/mattbw/backend/Makefile
  soc2013/mattbw/backend/jobs.c
  soc2013/mattbw/backend/jobs.h

Modified: soc2013/mattbw/backend/Makefile
==============================================================================
--- soc2013/mattbw/backend/Makefile	Wed Aug  7 11:25:34 2013	(r255637)
+++ soc2013/mattbw/backend/Makefile	Wed Aug  7 11:35:49 2013	(r255638)
@@ -53,6 +53,9 @@
 		query/do.c			\
 		query/match.c
 
+SRCS+=						\
+		jobs/check.c	
+
 LIBDIR=		/usr/local/lib/packagekit-backend
 
 PKGS= 		pkg gio-2.0 gio-unix-2.0

Modified: soc2013/mattbw/backend/jobs.c
==============================================================================
--- soc2013/mattbw/backend/jobs.c	Wed Aug  7 11:25:34 2013	(r255637)
+++ soc2013/mattbw/backend/jobs.c	Wed Aug  7 11:35:49 2013	(r255638)
@@ -31,10 +31,10 @@
 #include "event.h"		/* event_cb */
 #include "utils.h"		/* ERR */
 #include "jobs.h"		/* jobs_... */
+#include "jobs/check.h"		/* jobs_check_... */
 #include "pkgutils.h"		/* pkgutils_... */
 
-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 bool jobs_do_apply(const struct jobs_spec *spec, struct pkg_jobs *jobs);
 static bool jobs_do_check(const struct jobs_spec *spec, struct pkg_jobs *jobs, gchar **package_ids, guint count);
 static bool jobs_do_multiple_repos(struct pkgdb *db, const struct jobs_spec *spec, gchar **package_ids, guint count);
@@ -72,60 +72,7 @@
 	return success;
 }
 
-/* Checks a solved job against a string vector of PackageIDs to ensure any
- * packages that match the PackageIDs match them fully.
- */
-bool
-jobs_check_package_ids(struct pkg_jobs *jobs, gchar **package_ids,
-    guint count, bool reject_non_updates)
-{
-	bool		success;
-	bool		split_success;
-	unsigned int	i;
-	gchar	     ***id_splits;
-
-	assert(jobs != NULL);
-	assert(package_ids != NULL);
-
-	success = false;
-	id_splits = NULL;
-
-	count = g_strv_length(package_ids);
-	if (count == 0)
-		goto cleanup;
-
-	/* Split all the IDs first so we don't have to do it multiple times */
-	id_splits = calloc(count, sizeof(gchar **));
-	if (id_splits == NULL)
-		goto cleanup;
 
-	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;
-			break;
-		}
-	}
-	if (!split_success) {
-		goto cleanup;
-	}
-
-	/* Now do the actual checking, per package. */
-	success = jobs_check_split_package_ids(jobs, id_splits, count,
-	    reject_non_updates);
-
-cleanup:
-	if (id_splits != NULL) {
-		for (i = 0; i < count; i++)
-			g_strfreev(id_splits[i]);
-		free(id_splits);
-	}
-
-	/*pkg_free(pkg);*/
-
-	return success;
-}
 
 /* Performs a job from a job specification. */
 bool
@@ -167,84 +114,7 @@
 	return success;
 }
 
-static bool
-jobs_check_id_on_package(struct pkg *pkg, gchar **split_id,
-    const char *name, const char *version)
-{
-	bool		success;
-	gchar	       *match_id;
-
-	assert(pkg != NULL);
-	assert(split_id != NULL);
-	assert(name != NULL);
-	assert(version != 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)) {
-		/* 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);
-		}
-	}
-
-	return success;
-}
-
-
-static bool
-jobs_check_split_package_ids(struct pkg_jobs *jobs, gchar ***id_splits,
-    guint count, bool reject_non_updates)
-{
-	bool		success;
-	guint		i;
-	int		err;
-	const char     *name;
-	const char     *version;
-	struct pkg     *pkg;
-
-	assert(jobs != NULL);
-	assert(id_splits != NULL);
-	assert(0 < count);
-
-	success = true;
- 	while (success) {
- 		err = pkg_jobs(jobs, &pkg);
- 		if (err != EPKG_OK) {
- 			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) {
- 				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;
-	 		}
- 		}
- 	}
 
- 	return success;
- }
 
 /*
  * Performs a job on a batch of PackageIDs whose repos may be different.

Modified: soc2013/mattbw/backend/jobs.h
==============================================================================
--- soc2013/mattbw/backend/jobs.h	Wed Aug  7 11:25:34 2013	(r255637)
+++ soc2013/mattbw/backend/jobs.h	Wed Aug  7 11:35:49 2013	(r255638)
@@ -40,7 +40,6 @@
 };
 
 bool		jobs_apply(struct pkg_jobs *jobs, PkBackend *backend, PkErrorEnum no_jobs, PkErrorEnum jobs_failed);
-bool		jobs_check_package_ids(struct pkg_jobs *jobs, gchar **package_ids, guint count, bool reject_non_updates);
 bool		jobs_do(const struct jobs_spec *spec);
 char	      **jobs_add_package_ids(struct pkg_jobs *jobs, gchar **package_ids, guint count);
 void		jobs_emit_packages(struct pkg_jobs *jobs, PkBackend *backend, pkg_info_ptr info);

Added: soc2013/mattbw/backend/jobs/check.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/mattbw/backend/jobs/check.c	Wed Aug  7 11:35:49 2013	(r255638)
@@ -0,0 +1,169 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw@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 checking that a job matches up with a set of PackageIDs. */
+
+#include <assert.h>		/* assert */
+#include <glib.h>		/* gchar, g_... */
+#include <stdbool.h>		/* bool, true, false */
+#include <string.h>		/* strcmp */
+#include "../pk-backend.h"	/* pk_..., Pk... */
+#include "pkg.h"		/* pkg_... */
+
+#include "../utils.h"		/* ERR */
+#include "../pkgutils.h"	/* pkgutils_... */
+#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);
+
+/* Checks a solved job against a string vector of PackageIDs to ensure any
+ * packages that match the PackageIDs match them fully.
+ */
+bool
+jobs_check_package_ids(struct pkg_jobs *jobs, gchar **package_ids,
+    guint count, bool reject_non_updates)
+{
+	bool		success;
+	bool		split_success;
+	unsigned int	i;
+	gchar	     ***id_splits;
+
+	assert(jobs != NULL);
+	assert(package_ids != NULL);
+
+	success = false;
+	id_splits = NULL;
+
+	count = g_strv_length(package_ids);
+	if (count == 0)
+		goto cleanup;
+
+	/* Split all the IDs first so we don't have to do it multiple times */
+	id_splits = calloc(count, sizeof(gchar **));
+	if (id_splits == NULL)
+		goto cleanup;
+
+	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;
+			break;
+		}
+	}
+	if (!split_success) {
+		goto cleanup;
+	}
+
+	/* Now do the actual checking, per package. */
+	success = jobs_check_split_package_ids(jobs, id_splits, count,
+	    reject_non_updates);
+
+cleanup:
+	if (id_splits != NULL) {
+		for (i = 0; i < count; i++)
+			g_strfreev(id_splits[i]);
+		free(id_splits);
+	}
+
+	/*pkg_free(pkg);*/
+
+	return success;
+}
+
+static bool
+jobs_check_id_on_package(struct pkg *pkg, gchar **split_id,
+    const char *name, const char *version)
+{
+	bool		success;
+	gchar	       *match_id;
+
+	assert(pkg != NULL);
+	assert(split_id != NULL);
+	assert(name != NULL);
+	assert(version != 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)) {
+		/* 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);
+		}
+	}
+
+	return success;
+}
+
+
+static bool
+jobs_check_split_package_ids(struct pkg_jobs *jobs, gchar ***id_splits,
+    guint count, bool reject_non_updates)
+{
+	bool		success;
+	guint		i;
+	int		err;
+	const char     *name;
+	const char     *version;
+	struct pkg     *pkg;
+
+	assert(jobs != NULL);
+	assert(id_splits != NULL);
+	assert(0 < count);
+
+	success = true;
+ 	while (success) {
+ 		err = pkg_jobs(jobs, &pkg);
+ 		if (err != EPKG_OK) {
+ 			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) {
+ 				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;
+	 		}
+ 		}
+ 	}
+
+ 	return success;
+ }

Added: soc2013/mattbw/backend/jobs/check.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/mattbw/backend/jobs/check.h	Wed Aug  7 11:35:49 2013	(r255638)
@@ -0,0 +1,30 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw@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.
+ */
+
+#ifndef _PKGNG_BACKEND_JOBS_CHECK_H_
+#define _PKGNG_BACKEND_JOBS_CHECK_H_
+
+#include <glib.h>		/* gchar */
+#include <stdbool.h>		/* bool */
+#include "../pkg.h"		/* pkg_... */
+
+bool		jobs_check_package_ids(struct pkg_jobs *jobs, gchar **package_ids, guint count, bool reject_non_updates);
+
+#endif				/* !_PKGNG_BACKEND_JOBS_CHECK_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308071135.r77BZnXw042082>