[packagekit] packagekit: Branch 'master' - 5 commits

Richard Hughes hughsient at kemper.freedesktop.org
Tue Jan 8 10:20:22 PST 2008


 backends/ipkg/pk-backend-ipkg.c |  197 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 174 insertions(+), 23 deletions(-)

New commits:
commit 851f736a7518a6bc816485153aae8c2572da3c21
Author: Thomas Wood <thomas at openedhand.com>
Date:   Tue Jan 8 17:05:20 2008 +0000

    ipkg: implement update system function

diff --git a/backends/ipkg/pk-backend-ipkg.c b/backends/ipkg/pk-backend-ipkg.c
index dd2c34d..a95cbdd 100644
--- a/backends/ipkg/pk-backend-ipkg.c
+++ b/backends/ipkg/pk-backend-ipkg.c
@@ -389,6 +389,32 @@ backend_get_filters (PkBackend *backend, PkEnumList *elist)
 }
 
 
+static gboolean
+backend_update_system_thread (PkBackend *backend, gpointer data)
+{
+	gint err;
+	err = ipkg_packages_upgrade (&args);
+	if (err)
+		ipkg_unknown_error (backend, err, "Upgrading system");
+
+	pk_backend_finished (backend);
+	return (err != 0);
+}
+
+static void
+backend_update_system (PkBackend *backend)
+{
+	g_return_if_fail (backend != NULL);
+	pk_backend_change_status (backend, PK_STATUS_ENUM_UPDATE);
+	pk_backend_no_percentage_updates (backend);
+
+	pk_backend_thread_create (backend,
+		(PkBackendThreadFunc) backend_update_system_thread,
+		NULL);
+}
+
+
+
 PK_BACKEND_OPTIONS (
 	"ipkg",					/* description */
 	"Thomas Wood <thomas at openedhand.com>",	/* author */
@@ -414,7 +440,7 @@ PK_BACKEND_OPTIONS (
 	NULL,					/* search_group */
 	backend_search_name,			/* search_name */
 	NULL,					/* update_package */
-	NULL,					/* update_system */
+	backend_update_system,			/* update_system */
 	NULL,					/* get_repo_list */
 	NULL,					/* repo_enable */
 	NULL					/* repo_set_data */
commit 6616dbc388830d427055614d79a93115fcc4a21a
Author: Thomas Wood <thomas at openedhand.com>
Date:   Tue Jan 8 16:40:01 2008 +0000

    ipkg: Add Installed, Development and GUI filter support

diff --git a/backends/ipkg/pk-backend-ipkg.c b/backends/ipkg/pk-backend-ipkg.c
index a62cb3d..dd2c34d 100644
--- a/backends/ipkg/pk-backend-ipkg.c
+++ b/backends/ipkg/pk-backend-ipkg.c
@@ -30,6 +30,15 @@
 #define IPKG_LIB
 #include <libipkg.h>
 
+enum filters {
+	PKG_INSTALLED = 1,
+	PKG_NOT_INSTALLED = 2,
+	PKG_DEVEL = 4,
+	PKG_NOT_DEVEL = 8,
+	PKG_GUI = 16,
+	PKG_NOT_GUI = 32
+};
+
 /* global config structures */
 static ipkg_conf_t global_conf;
 static args_t args;
@@ -66,6 +75,57 @@ ipkg_unknown_error (PkBackend *backend, gint error_code, gchar *failed_cmd)
 }
 
 /**
+ * ipkg_is_gui_pkg:
+ *
+ * check an ipkg package for known GUI dependancies
+ */
+static gboolean
+ipkg_is_gui_pkg (pkg_t *pkg)
+{
+  gint i;
+
+  for (i = 0; i < pkg->depends_count; i++)
+  {
+    if (g_strrstr (pkg->depends_str[i], "gtk"))
+      return TRUE;
+  }
+  return FALSE;
+}
+
+/**
+ * parse_filter:
+ */
+static int
+parse_filter (const gchar *filter)
+{
+	gchar **sections = NULL;
+	gint i = 0;
+	gint retval = 0;
+
+	sections = g_strsplit (filter, ";", 0);
+	while (sections[i]) {
+		if (strcmp(sections[i], "installed") == 0)
+			retval = retval | PKG_INSTALLED;
+		if (strcmp(sections[i], "~installed") == 0)
+			retval = retval | PKG_NOT_INSTALLED;
+		if (strcmp(sections[i], "devel") == 0)
+			retval = retval | PKG_DEVEL;
+		if (strcmp(sections[i], "~devel") == 0)
+			retval = retval | PKG_NOT_DEVEL;
+		if (strcmp(sections[i], "gui") == 0)
+			retval = retval | PKG_GUI;
+		if (strcmp(sections[i], "~gui") == 0)
+			retval = retval | PKG_NOT_GUI;
+		i++;
+	}
+	g_strfreev (sections);
+
+	return retval;
+}
+
+
+
+/**
  * backend_initalize:
  */
 static void
@@ -177,32 +237,47 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
  * backend_search_name:
  */
 static gboolean
-backend_search_name_thread (PkBackend *backend, gchar *search)
+backend_search_name_thread (PkBackend *backend, gchar *params[2])
 {
 	int i;
 	pkg_vec_t *available;
 	pkg_t *pkg;
+	gchar *search;
+	gint filter;
 
-	g_return_val_if_fail ((search), FALSE);
-
-	ipkg_cb_message = ipkg_debug;
+	search = params[0];
+	filter = GPOINTER_TO_INT (params[1]);
 
 	available = pkg_vec_alloc();
 	pkg_hash_fetch_available (&global_conf.pkg_hash, available);
 	for (i=0; i < available->len; i++) {
 		char *uid;
 		pkg = available->pkgs[i];
-		if (g_strrstr (pkg->name, search)) {
-			uid = g_strdup_printf ("%s;%s;%s;",
-				pkg->name, pkg->version, pkg->architecture);
-
-			pk_backend_package (backend, PK_INFO_ENUM_AVAILABLE, uid,pkg->description);
-		}
+		if (!g_strrstr (pkg->name, search))
+			continue;
+		if ((filter & PKG_DEVEL) && !g_strrstr (pkg->name, "-dev"))
+			continue;
+		if ((filter & PKG_NOT_DEVEL) && g_strrstr (pkg->name, "-dev"))
+			continue;
+		if ((filter & PKG_GUI) && !ipkg_is_gui_pkg (pkg))
+			continue;
+		if ((filter & PKG_NOT_GUI) && ipkg_is_gui_pkg (pkg))
+			continue;
+		if ((filter & PKG_INSTALLED) && (pkg->state_status == SS_NOT_INSTALLED))
+			continue;
+		if ((filter & PKG_NOT_INSTALLED) && (pkg->state_status != SS_NOT_INSTALLED))
+			continue;
+
+		uid = g_strdup_printf ("%s;%s;%s;",
+			pkg->name, pkg->version, pkg->architecture);
+
+		pk_backend_package (backend, PK_INFO_ENUM_AVAILABLE, uid,pkg->description);
 	}
 
 	pkg_vec_free(available);
 	pk_backend_finished (backend);
 
+	g_free (params);
 	g_free (search);
 	return TRUE;
 }
@@ -210,13 +285,22 @@ backend_search_name_thread (PkBackend *backend, gchar *search)
 static void
 backend_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
 {
+	gint filter_enum;
+	gpointer *params;
+
 	g_return_if_fail (backend != NULL);
-	char *foo = g_strdup (search);
 
 	pk_backend_change_status (backend, PK_STATUS_ENUM_QUERY);
 	pk_backend_no_percentage_updates (backend);
 
-	pk_backend_thread_create (backend,(PkBackendThreadFunc) backend_search_name_thread, foo);
+	filter_enum = parse_filter (filter);
+
+	/* params is a small array we can pack our thread parameters into */
+	params = g_new0 (gpointer, 2);
+	params[0] = g_strdup (search);
+	params[1] = GINT_TO_POINTER (filter_enum);
+
+	pk_backend_thread_create (backend,(PkBackendThreadFunc) backend_search_name_thread, params);
 }
 
 static gboolean
@@ -290,13 +374,28 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
 
 }
 
+/**
+ * backend_get_filters:
+ */
+static void
+backend_get_filters (PkBackend *backend, PkEnumList *elist)
+{
+	g_return_if_fail (backend != NULL);
+	pk_enum_list_append_multiple (elist,
+				      PK_FILTER_ENUM_INSTALLED,
+				      PK_FILTER_ENUM_DEVELOPMENT,
+				      PK_FILTER_ENUM_GUI,
+				      -1);
+}
+
+
 PK_BACKEND_OPTIONS (
 	"ipkg",					/* description */
 	"Thomas Wood <thomas at openedhand.com>",	/* author */
 	backend_initalize,			/* initalize */
 	backend_destroy,			/* destroy */
 	NULL,					/* get_groups */
-	NULL,					/* get_filters */
+	backend_get_filters,			/* get_filters */
 	NULL,					/* cancel */
 	NULL,					/* get_depends */
 	backend_get_description,		/* get_description */
commit 15faec61222a7dd092fc3a5f68c9fc9cd4dd60fb
Author: Thomas Wood <thomas at openedhand.com>
Date:   Tue Jan 8 12:45:47 2008 +0000

    ipkg: free last_error on backend_destroy

diff --git a/backends/ipkg/pk-backend-ipkg.c b/backends/ipkg/pk-backend-ipkg.c
index dfdd785..a62cb3d 100644
--- a/backends/ipkg/pk-backend-ipkg.c
+++ b/backends/ipkg/pk-backend-ipkg.c
@@ -108,6 +108,7 @@ backend_destroy (PkBackend *backend)
 	/* this appears to (sometimes) be freed elsewhere ... */
 	/* ipkg_conf_deinit (&global_conf); */
 	args_deinit (&args);
+	g_free (last_error);
 }
 
 
commit a146189f27d3d96c07c42a2f451943869952391d
Author: Thomas Wood <thomas at openedhand.com>
Date:   Tue Jan 8 12:04:25 2008 +0000

    ipkg: improve error reporting

diff --git a/backends/ipkg/pk-backend-ipkg.c b/backends/ipkg/pk-backend-ipkg.c
index 2e5dca2..dfdd785 100644
--- a/backends/ipkg/pk-backend-ipkg.c
+++ b/backends/ipkg/pk-backend-ipkg.c
@@ -36,15 +36,35 @@ static args_t args;
 
 /* Ipkg message callback function */
 extern ipkg_message_callback ipkg_cb_message;
+static gchar *last_error;
 
 int
 ipkg_debug (ipkg_conf_t *conf, message_level_t level, char *msg)
 {
-	if (level == 0)
+	if (level != 0)
+		return 0;
+
+	/* print messages only if in verbose mode */
+	if (pk_debug_enabled ())
 		printf ("IPKG <%d>: %s", level, msg);
+
+	/* free the last error message and store the new one */
+	g_free (last_error);
+	last_error = g_strdup (msg);
 	return 0;
 }
 
+static void
+ipkg_unknown_error (PkBackend *backend, gint error_code, gchar *failed_cmd)
+{
+	gchar *msg;
+
+	msg = g_strdup_printf ("%s failed with error code %d. Last message was:\n\n%s", failed_cmd, error_code, last_error);
+	pk_backend_error_code (backend, PK_ERROR_ENUM_UNKNOWN, msg);
+
+	g_free (msg);
+}
+
 /**
  * backend_initalize:
  */
@@ -60,6 +80,9 @@ backend_initalize (PkBackend *backend)
 	 * here */
 	setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
 
+	last_error = NULL;
+	ipkg_cb_message = ipkg_debug;
+
 	memset(&global_conf, 0 ,sizeof(global_conf));
 	memset(&args, 0 ,sizeof(args));
 
@@ -71,7 +94,7 @@ backend_initalize (PkBackend *backend)
 
 	err = ipkg_conf_init (&global_conf, &args);
 	if (err) {
-		pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "init failed");
+		ipkg_unknown_error (backend, err, "Initialization");
 	}
 }
 
@@ -123,13 +146,9 @@ backend_refresh_cache_thread (PkBackend *backend, gpointer data)
 {
 	int ret;
 
-	/* set up debug if in verbose mode */
-	if (pk_debug_enabled ())
-		ipkg_cb_message = ipkg_debug;
-
 	ret = ipkg_lists_update (&args);
 	if (ret) {
-		pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "update failed");
+		ipkg_unknown_error (backend, ret, "Refreshing cache");
 	}
 	pk_backend_finished (backend);
 
@@ -218,7 +237,7 @@ backend_install_package_thread (PkBackend *backend, gchar *package_id)
 
 	err = ipkg_packages_install (&args, pi->name);
 	if (err != 0)
-		pk_backend_error_code (backend, PK_ERROR_ENUM_UNKNOWN, "Install failed");
+		ipkg_unknown_error (backend, err, "Install");
 
 	g_free (package_id);
 	pk_package_id_free (pi);
@@ -249,7 +268,7 @@ backend_remove_package_thread (PkBackend *backend, gchar *package_id)
 	err = ipkg_packages_remove (&args, pi->name, 0);
 	/* TODO: improve error reporting */
 	if (err != 0)
-		pk_backend_error_code (backend, PK_ERROR_ENUM_UNKNOWN, "Install failed");
+		ipkg_unknown_error (backend, err, "Install");
 
 	g_free (package_id);
 	pk_package_id_free (pi);
commit bd91732106cf71ab6a63b6bbfbcc2d2c31f8cd4c
Author: Thomas Wood <thomas at openedhand.com>
Date:   Tue Jan 8 10:23:48 2008 +0000

    ipkg: set PATH env variable to a well known value

diff --git a/backends/ipkg/pk-backend-ipkg.c b/backends/ipkg/pk-backend-ipkg.c
index a19e327..2e5dca2 100644
--- a/backends/ipkg/pk-backend-ipkg.c
+++ b/backends/ipkg/pk-backend-ipkg.c
@@ -54,6 +54,12 @@ backend_initalize (PkBackend *backend)
 	int err;
 	g_return_if_fail (backend != NULL);
 
+	/* Ipkg requires the PATH env variable to be set to find wget when
+	 * downloading packages. PackageKit unsets all env variables as a
+	 * security precaution, so we need to set PATH to something sensible
+	 * here */
+	setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
+
 	memset(&global_conf, 0 ,sizeof(global_conf));
 	memset(&args, 0 ,sizeof(args));
 



More information about the PackageKit mailing list