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

Richard Hughes hughsient at kemper.freedesktop.org
Thu Oct 11 15:30:46 PDT 2007


 TODO                      |   14 --
 libpackagekit/pk-client.c |  272 ++++++++++++++++++++++++++++++++++++++++++++--
 libpackagekit/pk-client.h |    5 
 3 files changed, 266 insertions(+), 25 deletions(-)

New commits:
diff-tree e197b6207d658e967b4d9cf43eba841c2b19f620 (from c242f68b978c8b87d209415f8a584c733ebaee70)
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Oct 11 23:29:39 2007 +0100

    update TODO

diff --git a/TODO b/TODO
index d66a139..9f81e34 100644
--- a/TODO
+++ b/TODO
@@ -1,8 +1,5 @@
 Order of no particular importance:
 
-*** pk-update-icon (client) ***
-* Don't re-run get-updates when selecting "Show updates" from the update icon, just populate it with the previous results.
-
 *** Add new callback for status ***
 TimeRemaining()
 
@@ -13,8 +10,6 @@ RepoSetData(s=rid,s=data,s=value)
 
 *** pk-application (client) ***
 Use an icons for installed and not-installed rather than tickboxes
-Refresh the query list after an install or remove (means saving the query and re-issuing)
-** RELEASE BLOCKER **
 
 *** Prepare download to refresh system ***
 Either use a flag or a new method. I'm not sure which yet.
@@ -25,10 +20,6 @@ In fedora, if you add a signed repo you 
 *** Split up PolicyKit install into different types ***
 Have different permissions for signed and unsigned repos.
 
-*** task_client has to return GError ***
-Client programs using libpackagekit should know the error, rather than just
-"it failed"
-
 *** Handle rollbacks for select backends ***
 To do rollbacks sanely in PK we need a few things:
  * emit internal signal for SetTransactionData
diff-tree c242f68b978c8b87d209415f8a584c733ebaee70 (from 21e55033af5e8f34dde474ebbc7aab55a15dac8e)
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Oct 11 23:22:50 2007 +0100

    when package_id is NULL we can avoid a trip to the daemon. also reset the client when we requeue

diff --git a/libpackagekit/pk-client.c b/libpackagekit/pk-client.c
index 5c0db56..12b2c09 100644
--- a/libpackagekit/pk-client.c
+++ b/libpackagekit/pk-client.c
@@ -753,6 +753,12 @@ pk_client_get_role (PkClient *client, Pk
 		return FALSE;
 	}
 
+	/* we can avoid a trip to the daemon */
+	if (package_id == NULL) {
+		*role = client->priv->role;
+		return TRUE;
+	}
+
 	error = NULL;
 	ret = dbus_g_proxy_call (client->priv->proxy, "GetRole", &error,
 				 G_TYPE_STRING, client->priv->tid,
@@ -1919,6 +1925,9 @@ pk_client_requeue (PkClient *client)
 		return FALSE;
 	}
 
+	/* reset this client, which doesn't clear cached data */
+	pk_client_reset (client);
+
 	/* do the correct action with the cached parameters */
 	if (client->priv->role == PK_ROLE_ENUM_GET_DEPENDS) {
 		pk_client_get_depends (client, client->priv->xcached_package_id);
diff-tree 21e55033af5e8f34dde474ebbc7aab55a15dac8e (from 666a81a1072ac5315be3c1b7a8174b6ee4b87b57)
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Oct 11 22:56:13 2007 +0100

    save the cached parameter data to allow the PkClient to requeue

diff --git a/TODO b/TODO
index 70e8b9e..d66a139 100644
--- a/TODO
+++ b/TODO
@@ -16,11 +16,6 @@ Use an icons for installed and not-insta
 Refresh the query list after an install or remove (means saving the query and re-issuing)
 ** RELEASE BLOCKER **
 
-*** Client library has to be able to re_issue ***
-Need to save PkRole
-Need to save data in xcache (copy from pk-engine)
-We should refresh the search after an install in pk-application
-
 *** Prepare download to refresh system ***
 Either use a flag or a new method. I'm not sure which yet.
 
diff --git a/libpackagekit/pk-client.c b/libpackagekit/pk-client.c
index fe8a0e0..5c0db56 100644
--- a/libpackagekit/pk-client.c
+++ b/libpackagekit/pk-client.c
@@ -33,6 +33,7 @@
 #include <glib/gi18n.h>
 #include <dbus/dbus-glib.h>
 
+#include "pk-enum.h"
 #include "pk-client.h"
 #include "pk-connection.h"
 #include "pk-package-list.h"
@@ -49,16 +50,24 @@ static void     pk_client_finalize	(GObj
 
 struct PkClientPrivate
 {
-	DBusGConnection	*connection;
-	DBusGProxy	*proxy;
-	gboolean	 is_finished;
-	gboolean	 use_buffer;
-	gchar		*tid;
-	PkPackageList	*package_list;
-	PkConnection	*pconnection;
-	PkPolkitClient	*polkit;
-	PkRestartEnum	 require_restart;
-	PkStatusEnum	 last_status;
+	DBusGConnection		*connection;
+	DBusGProxy		*proxy;
+	gboolean		 is_finished;
+	gboolean		 use_buffer;
+	gchar			*tid;
+	PkPackageList		*package_list;
+	PkConnection		*pconnection;
+	PkPolkitClient		*polkit;
+	PkRestartEnum		 require_restart;
+	PkStatusEnum		 last_status;
+	PkRoleEnum		 role;
+	gboolean		 xcached_force;
+	gboolean		 xcached_allow_deps;
+	gchar			*xcached_package_id;
+	gchar			*xcached_transaction_id;
+	gchar			*xcached_full_path;
+	gchar			*xcached_filter;
+	gchar			*xcached_search;
 };
 
 typedef enum {
@@ -962,6 +971,10 @@ pk_client_search_name (PkClient *client,
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_SEARCH_NAME;
+	client->priv->xcached_filter = g_strdup (filter);
+	client->priv->xcached_search = g_strdup (search);
 
 	error = NULL;
 	ret = dbus_g_proxy_call (client->priv->proxy, "SearchName", &error,
@@ -1003,6 +1016,10 @@ pk_client_search_details (PkClient *clie
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_SEARCH_DETAILS;
+	client->priv->xcached_filter = g_strdup (filter);
+	client->priv->xcached_search = g_strdup (search);
 
 	error = NULL;
 	ret = dbus_g_proxy_call (client->priv->proxy, "SearchDetails", &error,
@@ -1044,6 +1061,10 @@ pk_client_search_group (PkClient *client
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_SEARCH_GROUP;
+	client->priv->xcached_filter = g_strdup (filter);
+	client->priv->xcached_search = g_strdup (search);
 
 	error = NULL;
 	ret = dbus_g_proxy_call (client->priv->proxy, "SearchGroup", &error,
@@ -1085,6 +1106,10 @@ pk_client_search_file (PkClient *client,
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_SEARCH_FILE;
+	client->priv->xcached_filter = g_strdup (filter);
+	client->priv->xcached_search = g_strdup (search);
 
 	error = NULL;
 	ret = dbus_g_proxy_call (client->priv->proxy, "SearchFile", &error,
@@ -1126,6 +1151,9 @@ pk_client_get_depends (PkClient *client,
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_GET_DEPENDS;
+	client->priv->xcached_package_id = g_strdup (package);
 
 	error = NULL;
 	ret = dbus_g_proxy_call (client->priv->proxy, "GetDepends", &error,
@@ -1166,6 +1194,9 @@ pk_client_get_requires (PkClient *client
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_GET_REQUIRES;
+	client->priv->xcached_package_id = g_strdup (package);
 
 	error = NULL;
 	ret = dbus_g_proxy_call (client->priv->proxy, "GetRequires", &error,
@@ -1206,6 +1237,9 @@ pk_client_get_update_detail (PkClient *c
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_GET_UPDATE_DETAIL;
+	client->priv->xcached_package_id = g_strdup (package);
 
 	error = NULL;
 	ret = dbus_g_proxy_call (client->priv->proxy, "GetUpdateDetail", &error,
@@ -1229,6 +1263,49 @@ pk_client_get_update_detail (PkClient *c
 }
 
 /**
+ * pk_client_rollback:
+ **/
+gboolean
+pk_client_rollback (PkClient *client, const gchar *transaction_id)
+{
+	gboolean ret;
+	GError *error;
+
+	g_return_val_if_fail (client != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_CLIENT (client), FALSE);
+
+	/* check to see if we already have a transaction */
+	ret = pk_client_allocate_transaction_id (client);
+	if (ret == FALSE) {
+		pk_warning ("Failed to get transaction ID");
+		return FALSE;
+	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_GET_UPDATE_DETAIL;
+	client->priv->xcached_transaction_id = g_strdup (transaction_id);
+
+	error = NULL;
+	ret = dbus_g_proxy_call (client->priv->proxy, "Rollback", &error,
+				 G_TYPE_STRING, client->priv->tid,
+				 G_TYPE_STRING, transaction_id,
+				 G_TYPE_INVALID,
+				 G_TYPE_INVALID);
+	if (error != NULL) {
+		const gchar *error_name;
+		error_name = pk_client_get_error_name (error);
+		pk_debug ("ERROR: %s: %s", error_name, error->message);
+		g_error_free (error);
+	}
+	if (ret == FALSE) {
+		/* abort as the DBUS method failed */
+		pk_warning ("Rollback failed!");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+/**
  * pk_client_resolve:
  **/
 gboolean
@@ -1246,6 +1323,9 @@ pk_client_resolve (PkClient *client, con
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_RESOLVE;
+	client->priv->xcached_package_id = g_strdup (package);
 
 	error = NULL;
 	ret = dbus_g_proxy_call (client->priv->proxy, "Resolve", &error,
@@ -1286,6 +1366,9 @@ pk_client_get_description (PkClient *cli
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_GET_DESCRIPTION;
+	client->priv->xcached_package_id = g_strdup (package);
 
 	error = NULL;
 	ret = dbus_g_proxy_call (client->priv->proxy, "GetDescription", &error,
@@ -1313,7 +1396,7 @@ pk_client_get_description (PkClient *cli
  **/
 gboolean
 pk_client_remove_package_action (PkClient *client, const gchar *package,
-				      gboolean allow_deps, GError **error)
+				 gboolean allow_deps, GError **error)
 {
 	gboolean ret;
 
@@ -1353,6 +1436,10 @@ pk_client_remove_package (PkClient *clie
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_REMOVE_PACKAGE;
+	client->priv->xcached_allow_deps = allow_deps;
+	client->priv->xcached_package_id = g_strdup (package);
 
 	/* hopefully do the operation first time */
 	ret = pk_client_remove_package_action (client, package, allow_deps, &error);
@@ -1395,6 +1482,9 @@ pk_client_refresh_cache (PkClient *clien
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_REFRESH_CACHE;
+	client->priv->xcached_force = force;
 
 	error = NULL;
 	ret = dbus_g_proxy_call (client->priv->proxy, "RefreshCache", &error,
@@ -1460,6 +1550,9 @@ pk_client_install_package (PkClient *cli
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_INSTALL_PACKAGE;
+	client->priv->xcached_package_id = g_strdup (package_id);
 
 	/* hopefully do the operation first time */
 	ret = pk_client_install_package_action (client, package_id, &error);
@@ -1485,6 +1578,76 @@ pk_client_install_package (PkClient *cli
 }
 
 /**
+ * pk_client_update_package_action:
+ **/
+gboolean
+pk_client_update_package_action (PkClient *client, const gchar *package, GError **error)
+{
+	gboolean ret;
+
+	g_return_val_if_fail (client != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_CLIENT (client), FALSE);
+
+	*error = NULL;
+	ret = dbus_g_proxy_call (client->priv->proxy, "UpdatePackage", error,
+				 G_TYPE_STRING, client->priv->tid,
+				 G_TYPE_STRING, package,
+				 G_TYPE_INVALID,
+				 G_TYPE_INVALID);
+	if (ret == FALSE) {
+		/* abort as the DBUS method failed */
+		pk_warning ("UpdatePackage failed!");
+		return FALSE;
+	}
+	return TRUE;
+}
+
+/**
+ * pk_client_update_package:
+ **/
+gboolean
+pk_client_update_package (PkClient *client, const gchar *package_id)
+{
+	gboolean ret;
+	GError *error;
+
+	g_return_val_if_fail (client != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_CLIENT (client), FALSE);
+
+	/* check to see if we already have a transaction */
+	ret = pk_client_allocate_transaction_id (client);
+	if (ret == FALSE) {
+		pk_warning ("Failed to get transaction ID");
+		return FALSE;
+	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_INSTALL_PACKAGE;
+	client->priv->xcached_package_id = g_strdup (package_id);
+
+	/* hopefully do the operation first time */
+	ret = pk_client_update_package_action (client, package_id, &error);
+
+	/* we were refused by policy then try to get auth */
+	if (ret == FALSE) {
+		if (pk_polkit_client_error_denied_by_policy (error) == TRUE) {
+			/* retry the action if we succeeded */
+			if (pk_polkit_client_gain_privilege_str (client->priv->polkit, error->message) == TRUE) {
+				pk_debug ("gained priv");
+				g_error_free (error);
+				/* do it all over again */
+				ret = pk_client_install_package_action (client, package_id, &error);
+			}
+		}
+		if (error != NULL) {
+			pk_debug ("ERROR: %s", error->message);
+			g_error_free (error);
+		}
+	}
+
+	return ret;
+}
+
+/**
  * pk_client_install_file_action:
  **/
 gboolean
@@ -1527,6 +1690,9 @@ pk_client_install_file (PkClient *client
 		pk_warning ("Failed to get transaction ID");
 		return FALSE;
 	}
+	/* save this so we can re-issue it */
+	client->priv->role = PK_ROLE_ENUM_INSTALL_FILE;
+	client->priv->xcached_full_path = g_strdup (file);
 
 	/* hopefully do the operation first time */
 	ret = pk_client_install_file_action (client, file, &error);
@@ -1739,6 +1905,68 @@ pk_client_get_filters (PkClient *client)
 }
 
 /**
+ * pk_client_requeue:
+ */
+gboolean
+pk_client_requeue (PkClient *client)
+{
+	g_return_val_if_fail (client != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_CLIENT (client), FALSE);
+
+	/* we are no longer waiting, we are setting up */
+	if (client->priv->role == PK_ROLE_ENUM_UNKNOWN) {
+		pk_warning ("role unknown!!");
+		return FALSE;
+	}
+
+	/* do the correct action with the cached parameters */
+	if (client->priv->role == PK_ROLE_ENUM_GET_DEPENDS) {
+		pk_client_get_depends (client, client->priv->xcached_package_id);
+	} else if (client->priv->role == PK_ROLE_ENUM_GET_UPDATE_DETAIL) {
+		pk_client_get_update_detail (client, client->priv->xcached_package_id);
+	} else if (client->priv->role == PK_ROLE_ENUM_RESOLVE) {
+		pk_client_resolve (client, client->priv->xcached_package_id);
+	} else if (client->priv->role == PK_ROLE_ENUM_ROLLBACK) {
+		pk_client_rollback (client, client->priv->xcached_transaction_id);
+	} else if (client->priv->role == PK_ROLE_ENUM_GET_DESCRIPTION) {
+		pk_client_get_description (client, client->priv->xcached_package_id);
+	} else if (client->priv->role == PK_ROLE_ENUM_GET_REQUIRES) {
+		pk_client_get_requires (client, client->priv->xcached_package_id);
+	} else if (client->priv->role == PK_ROLE_ENUM_GET_UPDATES) {
+		pk_client_get_updates (client);
+	} else if (client->priv->role == PK_ROLE_ENUM_SEARCH_DETAILS) {
+		pk_client_search_details (client, client->priv->xcached_filter,
+					  client->priv->xcached_search);
+	} else if (client->priv->role == PK_ROLE_ENUM_SEARCH_FILE) {
+		pk_client_search_file (client, client->priv->xcached_filter,
+				       client->priv->xcached_search);
+	} else if (client->priv->role == PK_ROLE_ENUM_SEARCH_GROUP) {
+		pk_client_search_group (client, client->priv->xcached_filter,
+					client->priv->xcached_search);
+	} else if (client->priv->role == PK_ROLE_ENUM_SEARCH_NAME) {
+		pk_client_search_name (client, client->priv->xcached_filter,
+				       client->priv->xcached_search);
+	} else if (client->priv->role == PK_ROLE_ENUM_INSTALL_PACKAGE) {
+		pk_client_install_package (client, client->priv->xcached_package_id);
+	} else if (client->priv->role == PK_ROLE_ENUM_INSTALL_FILE) {
+		pk_client_install_file (client, client->priv->xcached_full_path);
+	} else if (client->priv->role == PK_ROLE_ENUM_REFRESH_CACHE) {
+		pk_client_refresh_cache (client, client->priv->xcached_force);
+	} else if (client->priv->role == PK_ROLE_ENUM_REMOVE_PACKAGE) {
+		pk_client_remove_package (client, client->priv->xcached_package_id,
+					  client->priv->xcached_allow_deps);
+	} else if (client->priv->role == PK_ROLE_ENUM_UPDATE_PACKAGE) {
+		pk_client_update_package (client, client->priv->xcached_package_id);
+	} else if (client->priv->role == PK_ROLE_ENUM_UPDATE_SYSTEM) {
+		pk_client_update_system (client);
+	} else {
+		pk_warning ("role unknown");
+		return FALSE;
+	}
+	return TRUE;
+}
+
+/**
  * pk_client_class_init:
  **/
 static void
@@ -1855,8 +2083,14 @@ pk_client_init (PkClient *client)
 	client->priv->use_buffer = FALSE;
 	client->priv->last_status = PK_STATUS_ENUM_UNKNOWN;
 	client->priv->require_restart = PK_RESTART_ENUM_NONE;
+	client->priv->role = PK_ROLE_ENUM_UNKNOWN;
 	client->priv->is_finished = FALSE;
 	client->priv->package_list = pk_package_list_new ();
+	client->priv->xcached_package_id = NULL;
+	client->priv->xcached_transaction_id = NULL;
+	client->priv->xcached_full_path = NULL;
+	client->priv->xcached_filter = NULL;
+	client->priv->xcached_search = NULL;
 
 	/* check dbus connections, exit if not valid */
 	client->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
@@ -2008,6 +2242,13 @@ pk_client_finalize (GObject *object)
 	client = PK_CLIENT (object);
 	g_return_if_fail (client->priv != NULL);
 
+	/* free cached strings */
+	g_free (client->priv->xcached_package_id);
+	g_free (client->priv->xcached_transaction_id);
+	g_free (client->priv->xcached_full_path);
+	g_free (client->priv->xcached_filter);
+	g_free (client->priv->xcached_search);
+
 	/* disconnect signal handlers */
 	dbus_g_proxy_disconnect_signal (client->priv->proxy, "Finished",
 				        G_CALLBACK (pk_client_finished_cb), client);
diff --git a/libpackagekit/pk-client.h b/libpackagekit/pk-client.h
index 838baa0..dc57f77 100644
--- a/libpackagekit/pk-client.h
+++ b/libpackagekit/pk-client.h
@@ -104,11 +104,16 @@ gboolean	 pk_client_refresh_cache		(PkCl
 							 gboolean	 force);
 gboolean	 pk_client_install_package		(PkClient	*client,
 							 const gchar	*package_id);
+gboolean	 pk_client_update_package		(PkClient	*client,
+							 const gchar	*package_id);
 gboolean	 pk_client_install_file			(PkClient	*client,
 							 const gchar	*full_path);
 gboolean	 pk_client_resolve			(PkClient	*client,
 							 const gchar	*package);
+gboolean	 pk_client_rollback			(PkClient	*client,
+							 const gchar	*transaction_id);
 gboolean	 pk_client_cancel			(PkClient	*client);
+gboolean	 pk_client_requeue			(PkClient	*client);
 
 /* cached stuff */
 GPtrArray	*pk_client_get_package_buffer		(PkClient	*client);


More information about the PackageKit mailing list