socsvn commit: r253294 - soc2013/mattbw/dummy

mattbw at FreeBSD.org mattbw at FreeBSD.org
Thu Jun 20 19:29:26 UTC 2013


Author: mattbw
Date: Thu Jun 20 19:29:25 2013
New Revision: 253294
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253294

Log:
  Split off get-details implementation details to their own file.  Temporarily force clang in Makefile.

Added:
  soc2013/mattbw/dummy/get-details.c
  soc2013/mattbw/dummy/get-details.h
Modified:
  soc2013/mattbw/dummy/Makefile
  soc2013/mattbw/dummy/pk-backend-pkgng.c

Modified: soc2013/mattbw/dummy/Makefile
==============================================================================
--- soc2013/mattbw/dummy/Makefile	Thu Jun 20 18:25:10 2013	(r253293)
+++ soc2013/mattbw/dummy/Makefile	Thu Jun 20 19:29:25 2013	(r253294)
@@ -1,8 +1,11 @@
 # $FreeBSD$
 
+# Temporary
+CC=		clang
+
 LIB=		pk_backend_pkgng
 SHLIB_MAJOR=	1
-SRCS=		pk-backend-pkgng.c
+SRCS=		pk-backend-pkgng.c get-details.c
 
 USE_PK_PKGCONF=	0
 

Added: soc2013/mattbw/dummy/get-details.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/mattbw/dummy/get-details.c	Thu Jun 20 19:29:25 2013	(r253294)
@@ -0,0 +1,122 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at 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.
+ */
+
+#include <glib.h>
+#include "pk-backend.h"
+#include "pkg.h"
+
+gboolean
+get_details_check_matches(struct pkgdb_it *matches, gchar *id_name, gchar *id_version, gchar *id_arch, gchar *id_data, PkBackend *backend)
+{
+	gboolean	found;
+	int		err;
+	struct pkg	*match;
+
+	found = FALSE;
+	do {
+		err = pkgdb_it_next(matches, &match, PKG_LOAD_BASIC);
+		if (err == EPKG_OK) {
+			const char	*name;
+			const char	*version;
+			const char	*description;
+			const char	*arch;
+			const char	*reponame;
+			const char	*data;
+			const char	*www;
+			pkg_t		 type;
+
+			pkg_get2(match,
+			    PKG_NAME, &name,
+			    PKG_VERSION, &version,
+			    PKG_DESC, &description,
+			    PKG_ARCH, &arch,
+			    PKG_REPONAME, &reponame,
+			    PKG_WWW, &www);
+
+			if (type == PKG_FILE)
+				data = "local";
+			else if (type == PKG_INSTALLED)
+				data = "installed";
+			else
+				data = reponame;
+
+			if ((id_name == NULL || g_strcmp0(name, id_name) == 0) &&
+			    (id_version == NULL || g_strcmp0(version, id_version) == 0) &&
+			    (id_arch == NULL || g_strcmp0(arch, id_arch) == 0) &&
+			    (id_data == NULL || g_strcmp0(data, id_data) == 0)) {
+				gchar	       *new_id;
+
+				found = TRUE;
+				new_id = pk_package_id_build(name, version, arch, data);
+
+				/* TODO: implement category, size and licence */
+				pk_backend_details(backend,
+				    new_id,
+				    NULL,
+				    PK_GROUP_ENUM_PROGRAMMING,
+				    description, 
+				    www,
+				    0
+				);
+
+				g_free(new_id);
+			}
+		}
+	} while (err == EPKG_OK && found == FALSE);
+
+	if (found == FALSE)
+		pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, NULL);
+		
+	return found;
+}
+
+gboolean
+get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db)
+{
+	gchar	      **parts;
+	gboolean	success;
+
+	success = FALSE;
+
+	parts = pk_package_id_split(package_id);
+	if (parts == NULL) {
+		pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
+	} else {
+		struct pkgdb_it *packages;
+
+		packages = pkgdb_search(db, parts[PK_PACKAGE_ID_NAME], MATCH_EXACT, FIELD_NAME, NULL);
+
+		if (packages) {
+			success = get_details_check_matches(packages,
+			    parts[PK_PACKAGE_ID_NAME],
+			    parts[PK_PACKAGE_ID_VERSION],
+			    parts[PK_PACKAGE_ID_ARCH],
+			    parts[PK_PACKAGE_ID_DATA],
+			    backend);
+
+			pkgdb_it_free(packages);
+		} else
+			pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, NULL);
+
+		g_strfreev(parts);
+	}
+	
+	return success;
+}

Added: soc2013/mattbw/dummy/get-details.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/mattbw/dummy/get-details.h	Thu Jun 20 19:29:25 2013	(r253294)
@@ -0,0 +1,26 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at 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 _GET_DETAILS_H_
+#define _GET_DETAILS_H_
+
+gboolean get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db);
+
+#endif /* !_GET_DETAILS_H_ */

Modified: soc2013/mattbw/dummy/pk-backend-pkgng.c
==============================================================================
--- soc2013/mattbw/dummy/pk-backend-pkgng.c	Thu Jun 20 18:25:10 2013	(r253293)
+++ soc2013/mattbw/dummy/pk-backend-pkgng.c	Thu Jun 20 19:29:25 2013	(r253294)
@@ -30,6 +30,8 @@
 #include "pk-backend.h"
 #include "pkg.h"
 
+#include "get-details.h"
+
 /* static bodges */
 static guint	_progress_percentage = 0;
 static gulong	_signal_timeout = 0;
@@ -171,106 +173,6 @@
 	pk_backend_finished(backend);
 }
 
-
-gboolean
-get_details_check_matches(struct pkgdb_it *matches, gchar *id_name, gchar *id_version, gchar *id_arch, gchar *id_data, PkBackend *backend)
-{
-	gboolean	found;
-	int		err;
-	struct pkg	*match;
-
-	found = FALSE;
-	do {
-		err = pkgdb_it_next(matches, &match, PKG_LOAD_BASIC);
-		if (err == EPKG_OK) {
-			const char	*name;
-			const char	*version;
-			const char	*description;
-			const char	*arch;
-			const char	*reponame;
-			const char	*data;
-			const char	*www;
-			pkg_t		 type;
-
-			pkg_get2(match,
-			    PKG_NAME, &name,
-			    PKG_VERSION, &version,
-			    PKG_DESC, &description,
-			    PKG_ARCH, &arch,
-			    PKG_REPONAME, &reponame,
-			    PKG_WWW, &www);
-
-			if (type == PKG_FILE)
-				data = "local";
-			else if (type == PKG_INSTALLED)
-				data = "installed";
-			else
-				data = reponame;
-
-			if ((id_name == NULL || g_strcmp0(name, id_name) == 0) &&
-			    (id_version == NULL || g_strcmp0(version, id_version) == 0) &&
-			    (id_arch == NULL || g_strcmp0(arch, id_arch) == 0) &&
-			    (id_data == NULL || g_strcmp0(data, id_data) == 0)) {
-				gchar	       *new_id;
-
-				found = TRUE;
-				new_id = pk_package_id_build(name, version, arch, data);
-
-				/* TODO: implement category, size and licence */
-				pk_backend_details(backend,
-				    new_id,
-				    NULL,
-				    PK_GROUP_ENUM_PROGRAMMING,
-				    description, 
-				    www,
-				    0
-				);
-
-				g_free(new_id);
-			}
-		}
-	} while (err == EPKG_OK && found == FALSE);
-
-	if (found == FALSE)
-		pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, NULL);
-		
-	return found;
-}
-
-gboolean
-get_details_for(gchar *package_id, PkBackend *backend)
-{
-	gchar	      **parts;
-	gboolean	success;
-
-	success = FALSE;
-
-	parts = pk_package_id_split(package_id);
-	if (parts == NULL) {
-		pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
-	} else {
-		struct pkgdb_it *packages;
-
-		packages = pkgdb_search(priv.db, parts[PK_PACKAGE_ID_NAME], MATCH_EXACT, FIELD_NAME, NULL);
-
-		if (packages) {
-			success = get_details_check_matches(packages,
-			    parts[PK_PACKAGE_ID_NAME],
-			    parts[PK_PACKAGE_ID_VERSION],
-			    parts[PK_PACKAGE_ID_ARCH],
-			    parts[PK_PACKAGE_ID_DATA],
-			    backend);
-
-			pkgdb_it_free(packages);
-		} else
-			pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, NULL);
-
-		g_strfreev(parts);
-	}
-	
-	return success;
-}
-
 gboolean
 backend_get_details_thread(PkBackend *backend)
 {
@@ -285,8 +187,8 @@
 	len = g_strv_length(package_ids);
 
 	pk_backend_set_percentage(backend, 0);
-	for (i = 0, no_error_yet = TRUE; i < len, no_error_yet; i++) {
-		no_error_yet = get_details_for(package_ids[0], backend);
+	for (i = 0, no_error_yet = TRUE; i < len && no_error_yet; i++) {
+		no_error_yet = get_details_for(package_ids[0], backend, priv.db);
 		pk_backend_set_percentage(backend, ((i * 100) / len));
 	}
 	


More information about the svn-soc-all mailing list