Blob Blame Raw
diff --git a/backends/yum/yumBackend.py b/backends/yum/yumBackend.py
index 491f044..896d32b 100755
--- a/backends/yum/yumBackend.py
+++ b/backends/yum/yumBackend.py
@@ -1787,7 +1787,7 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
                         return
                     self._show_package(pkg, INFO_UNTRUSTED)
                 try:
-                    self._runYumTransaction(allow_skip_broken=True, only_simulate=TRANSACTION_FLAG_SIMULATE in transaction_flags)
+                    self._runYumTransaction(transaction_flags, allow_skip_broken=True)
                 except PkError, e:
                     self.error(e.code, e.details, exit=False)
             else:
@@ -2020,7 +2020,7 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
                     return
                 self._show_package(pkg, INFO_UNTRUSTED)
             try:
-                self._runYumTransaction(only_simulate=TRANSACTION_FLAG_SIMULATE in transaction_flags)
+                self._runYumTransaction(transaction_flags)
             except PkError, e:
                 self.error(e.code, e.details, exit=False)
         else:
@@ -2203,7 +2203,7 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
                 return
 
             try:
-                self._runYumTransaction(only_simulate=TRANSACTION_FLAG_SIMULATE in transaction_flags)
+                self._runYumTransaction(transaction_flags)
             except PkError, e:
                 self.error(e.code, e.details, exit=False)
                 return
@@ -2231,7 +2231,7 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
                             if not self.yumbase.tsInfo.pkgSack:
                                 self.yumbase.tsInfo.pkgSack = MetaSack()
                             try:
-                                self._runYumTransaction(only_simulate=TRANSACTION_FLAG_SIMULATE in transaction_flags)
+                                self._runYumTransaction(transaction_flags)
                             except PkError, e:
                                 self.error(e.code, e.details, exit=False)
                                 return
@@ -2344,7 +2344,7 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
                         return
                     self._show_package(pkg, INFO_UNTRUSTED)
                 try:
-                    self._runYumTransaction(allow_skip_broken=True, only_simulate=TRANSACTION_FLAG_SIMULATE in transaction_flags)
+                    self._runYumTransaction(transaction_flags, allow_skip_broken=True)
                 except PkError, e:
                     self.error(e.code, e.details, exit=False)
             else:
@@ -2361,7 +2361,7 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
                 or (notice and notice.get_metadata().has_key('reboot_suggested') and notice['reboot_suggested'])):
                 self.require_restart(RESTART_SYSTEM, self._pkg_to_id(pkg))
 
-    def _runYumTransaction(self, allow_remove_deps=None, allow_skip_broken=False, only_simulate=False):
+    def _runYumTransaction(self, transaction_flags, allow_remove_deps=None, allow_skip_broken=False):
         '''
         Run the yum Transaction
         This will only work with yum 3.2.4 or higher
@@ -2409,7 +2409,7 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
             raise PkError(ERROR_TRANSACTION_ERROR, message)
 
         # abort now we have the package list
-        if only_simulate:
+        if TRANSACTION_FLAG_SIMULATE in transaction_flags:
             package_list = []
             for txmbr in self.yumbase.tsInfo:
                 if txmbr.output_state in TransactionsInfoMap.keys():
@@ -2421,6 +2421,20 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
             self.percentage(100)
             return
 
+        if TRANSACTION_FLAG_ONLY_DOWNLOAD in transaction_flags:
+            package_list = []
+            for txmbr in self.yumbase.tsInfo:
+                if txmbr.output_state in (TS_UPDATE, TS_INSTALL):
+                    self._show_package(txmbr.po, INFO_DOWNLOADING)
+                    repo = self.yumbase.repos.getRepo(txmbr.po.repoid)
+                    try:
+                        path = repo.getPackage(txmbr.po)
+                    except IOError, e:
+                        self.error(ERROR_PACKAGE_DOWNLOAD_FAILED, "Cannot write to file", exit=False)
+                        return
+            self.percentage(100)
+            return
+
         try:
             rpmDisplay = PackageKitCallback(self)
             callback = ProcessTransPackageKitCallback(self)
@@ -2529,9 +2543,9 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
                         return
             try:
                 if not allowdep:
-                    self._runYumTransaction(allow_remove_deps=False, only_simulate=TRANSACTION_FLAG_SIMULATE in transaction_flags)
+                    self._runYumTransaction(transaction_flags, allow_remove_deps=False)
                 else:
-                    self._runYumTransaction(allow_remove_deps=True, only_simulate=TRANSACTION_FLAG_SIMULATE in transaction_flags)
+                    self._runYumTransaction(transaction_flags, allow_remove_deps=True)
             except PkError, e:
                 self.error(e.code, e.details, exit=False)
         else:
@@ -3173,6 +3187,9 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage):
         # default to 100% unless method overrides
         self.yumbase.conf.throttle = "90%"
 
+        # do not use parallel downloading
+        self.yumbase.conf.async = False
+
     def _setup_yum(self):
         try:
             # setup Yum Config
@@ -3349,17 +3366,18 @@ class PackageKitCallback(RPMBaseCallback):
                 self.base.message(MESSAGE_BACKEND_ERROR, "The constant '%s' was unknown, please report. details: %s" % (action, _to_unicode(e)))
 
         # set item percentage
-        #if package and te_total > 0:
-        #    val = (te_current*100L)/te_total
-        #    if self.curpkg:
-        #        self.base.item_percentage(self.base._pkg_to_id(self.curpkg), val)
+        if package and te_total > 0:
+            val = (te_current*100L)/te_total
+            if self.curpkg:
+                self.base.item_percentage(self.base._pkg_to_id(self.curpkg), val)
 
-        # find out the offset
+        # find out the start offset
         pct_start = StatusPercentageMap[STATUS_INSTALL]
 
         # do percentage
         if ts_total > 0:
             div = (100 - pct_start) / ts_total
+            val = (te_current*100L)/te_total
             pct = div * (ts_current - 1) + pct_start + ((div / 100.0) * val)
             self.base.percentage(pct)
 
diff --git a/contrib/systemd-updates/pk-offline-update.c b/contrib/systemd-updates/pk-offline-update.c
index 5d6604d..a6fdaaf 100644
--- a/contrib/systemd-updates/pk-offline-update.c
+++ b/contrib/systemd-updates/pk-offline-update.c
@@ -27,6 +27,7 @@
 
 #define PK_OFFLINE_UPDATE_RESULTS_GROUP		"PackageKit Offline Update Results"
 #define PK_OFFLINE_UPDATE_RESULTS_FILENAME	"/var/lib/PackageKit/offline-update-competed"
+#define PK_OFFLINE_PREPARED_UPDATE_FILENAME	"/var/lib/PackageKit/prepared-update"
 
 /**
  * pk_offline_update_set_plymouth_msg:
@@ -38,6 +39,9 @@ pk_offline_update_set_plymouth_msg (const gchar *msg)
 	gchar *cmd;
 	GError *error = NULL;
 
+	/* allow testing without sending commands to plymouth */
+	if (g_getenv ("PK_OFFLINE_UPDATE_TEST") != NULL)
+		return;
 	cmd = g_strdup_printf ("plymouth display-message --text=\"%s\"", msg);
 	ret = g_spawn_command_line_async (cmd, &error);
 	if (!ret) {
@@ -59,6 +63,9 @@ pk_offline_update_set_plymouth_mode (const gchar *mode)
 	GError *error = NULL;
 	gchar *cmdline;
 
+	/* allow testing without sending commands to plymouth */
+	if (g_getenv ("PK_OFFLINE_UPDATE_TEST") != NULL)
+		return;
 	cmdline = g_strdup_printf ("plymouth change-mode --%s", mode);
 	ret = g_spawn_command_line_async (cmdline, &error);
 	if (!ret) {
@@ -79,6 +86,9 @@ pk_offline_update_set_plymouth_percentage (guint percentage)
 	GError *error = NULL;
 	gchar *cmdline;
 
+	/* allow testing without sending commands to plymouth */
+	if (g_getenv ("PK_OFFLINE_UPDATE_TEST") != NULL)
+		return;
 	cmdline = g_strdup_printf ("plymouth system-update --progress=%i",
 				   percentage);
 	ret = g_spawn_command_line_async (cmdline, &error);
@@ -128,6 +138,10 @@ pk_offline_update_reboot (void)
 	GError *error = NULL;
 	GVariant *val = NULL;
 
+	/* allow testing without rebooting */
+	if (g_getenv ("PK_OFFLINE_UPDATE_TEST") != NULL)
+		return;
+
 	/* reboot using systemd */
 	pk_offline_update_set_plymouth_mode ("shutdown");
 	pk_offline_update_set_plymouth_msg ("Rebooting after installing updates...");
@@ -299,10 +313,13 @@ out:
 int
 main (int argc, char *argv[])
 {
+	gboolean ret;
+	gchar **package_ids = NULL;
+	gchar *packages_data = NULL;
 	GError *error = NULL;
 	gint retval;
-	PkTask *task = NULL;
 	PkResults *results;
+	PkTask *task = NULL;
 
 	/* setup */
 	g_type_init ();
@@ -314,16 +331,30 @@ main (int argc, char *argv[])
 		goto out;
 	}
 
+	/* get the list of packages to update */
+	ret = g_file_get_contents (PK_OFFLINE_PREPARED_UPDATE_FILENAME,
+				   &packages_data,
+				   NULL,
+				   &error);
+	if (!ret) {
+		retval = EXIT_FAILURE;
+		g_warning ("failed to read: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
 	/* just update the system */
 	task = pk_task_new ();
 	pk_task_set_interactive (task, FALSE);
 	pk_offline_update_set_plymouth_mode ("updates");
-	results = pk_client_update_system (PK_CLIENT (task),
-					   0,
-					   NULL, /* GCancellable */
-					   pk_offline_update_progress_cb,
-					   NULL, /* user_data */
-					   &error);
+	package_ids = g_strsplit (packages_data, "\n", -1);
+	results = pk_client_update_packages (PK_CLIENT (task),
+					     0,
+					     package_ids,
+					     NULL, /* GCancellable */
+					     pk_offline_update_progress_cb,
+					     NULL, /* user_data */
+					     &error);
 	if (results == NULL) {
 		retval = EXIT_FAILURE;
 		pk_offline_update_write_error (error);
@@ -332,11 +363,13 @@ main (int argc, char *argv[])
 		goto out;
 	}
 	pk_offline_update_write_results (results);
-	g_unlink ("/var/lib/PackageKit/prepared-update");
+	g_unlink (PK_OFFLINE_PREPARED_UPDATE_FILENAME);
 	retval = EXIT_SUCCESS;
 out:
 	g_unlink ("/system-update");
 	pk_offline_update_reboot ();
+	g_free (packages_data);
+	g_strfreev (package_ids);
 	if (task != NULL)
 		g_object_unref (task);
 	return retval;
diff --git a/lib/packagekit-glib2/pk-client.c b/lib/packagekit-glib2/pk-client.c
index 5613f3e..4af44a7 100644
--- a/lib/packagekit-glib2/pk-client.c
+++ b/lib/packagekit-glib2/pk-client.c
@@ -1204,7 +1204,7 @@ pk_client_signal_cb (GDBusProxy *proxy,
 	if (g_strcmp0 (signal_name, "Transaction") == 0) {
 		PkTransactionPast *item;
 		g_variant_get (parameters,
-			       "(&o&sb&su&su&s)",
+			       "(&o&sbuu&su&s)",
 			       &tmp_str[0],
 			       &tmp_str[1],
 			       &tmp_bool,
diff --git a/lib/packagekit-glib2/pk-progress.c b/lib/packagekit-glib2/pk-progress.c
index d1b7ff4..aa1b94f 100644
--- a/lib/packagekit-glib2/pk-progress.c
+++ b/lib/packagekit-glib2/pk-progress.c
@@ -266,6 +266,10 @@ pk_progress_set_role (PkProgress *progress, PkRoleEnum role)
 {
 	g_return_val_if_fail (PK_IS_PROGRESS (progress), FALSE);
 
+	/* ignore unknown as we don't want to replace a valid value */
+	if (role == PK_ROLE_ENUM_UNKNOWN)
+		return FALSE;
+
 	/* the same as before? */
 	if (progress->priv->role == role)
 		return FALSE;
diff --git a/src/pk-backend.c b/src/pk-backend.c
index b9ae2b8..477552f 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -1109,6 +1109,8 @@ pk_backend_set_item_progress (PkBackend *backend,
 			      const gchar *package_id,
 			      guint percentage)
 {
+	PkItemProgress *item;
+
 	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
 	g_return_val_if_fail (backend->priv->loaded, FALSE);
 
@@ -1125,9 +1127,15 @@ pk_backend_set_item_progress (PkBackend *backend,
 	}
 
 	/* emit */
+	item = pk_item_progress_new ();
+	g_object_set (item,
+		      "package-id", package_id,
+		      "percentage", percentage,
+		      NULL);
 	pk_backend_call_vfunc (backend,
 			       PK_BACKEND_SIGNAL_ITEM_PROGRESS,
-			       (gpointer) package_id); //FIXME
+			       item);
+	g_object_unref (item);
 	return TRUE;
 }
 
diff --git a/src/pk-transaction.c b/src/pk-transaction.c
index afdd563..c5a29f1 100644
--- a/src/pk-transaction.c
+++ b/src/pk-transaction.c
@@ -689,23 +689,24 @@ pk_transaction_category_cb (PkBackend *backend,
  **/
 static void
 pk_transaction_item_progress_cb (PkBackend *backend,
-				 const gchar *package_id,
-				 guint percentage,
+				 PkItemProgress *item_progress,
 				 PkTransaction *transaction)
 {
 	g_return_if_fail (PK_IS_TRANSACTION (transaction));
 	g_return_if_fail (transaction->priv->tid != NULL);
 
 	/* emit */
-	g_debug ("emitting item-progress %s, %u", package_id, percentage);
+	g_debug ("emitting item-progress %s, %u",
+		 pk_item_progress_get_package_id (item_progress),
+		 pk_item_progress_get_percentage (item_progress));
 	g_dbus_connection_emit_signal (transaction->priv->connection,
 				       NULL,
 				       transaction->priv->tid,
 				       PK_DBUS_INTERFACE_TRANSACTION,
 				       "ItemProgress",
 				       g_variant_new ("(su)",
-						      package_id,
-						      percentage),
+						      pk_item_progress_get_package_id (item_progress),
+						      pk_item_progress_get_percentage (item_progress)),
 				       NULL);
 }
 
@@ -1106,14 +1107,75 @@ pk_transaction_set_full_paths (PkTransaction *transaction,
 }
 
 /**
+ * pk_transaction_get_existing_prepared_updates:
+ **/
+static GPtrArray *
+pk_transaction_get_existing_prepared_updates (const gchar *filename)
+{
+	gboolean ret;
+	gchar **package_ids = NULL;
+	gchar *packages_data = NULL;
+	GError *error = NULL;
+	GPtrArray *packages;
+	guint i;
+
+	/* always return a valid array, even for failure */
+	packages = g_ptr_array_new_with_free_func (g_free);
+
+	/* does the file exist ? */
+	if (!g_file_test (filename, G_FILE_TEST_EXISTS))
+		goto out;
+
+	/* get the list of packages to update */
+	ret = g_file_get_contents (filename,
+				   &packages_data,
+				   NULL,
+				   &error);
+	if (!ret) {
+		g_warning ("failed to read: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* add them to the new array */
+	package_ids = g_strsplit (packages_data, "\n", -1);
+	for (i = 0; package_ids[i] != NULL; i++)
+		g_ptr_array_add (packages, g_strdup (package_ids[i]));
+out:
+	g_free (packages_data);
+	g_strfreev (package_ids);
+	return packages;
+}
+
+/**
+ * pk_transaction_array_str_exists:
+ **/
+static gboolean
+pk_transaction_array_str_exists (GPtrArray *array, const gchar *str)
+{
+	guint i;
+	const gchar *tmp;
+	for (i = 0; i < array->len; i++) {
+		tmp = g_ptr_array_index (array, i);
+		if (g_strcmp0 (tmp, str) == 0)
+			return TRUE;
+	}
+	return FALSE;
+}
+
+/**
  * pk_transaction_write_prepared_file:
  **/
 static void
 pk_transaction_write_prepared_file (PkTransaction *transaction)
 {
 	gboolean ret;
+	gchar **package_ids;
+	gchar *packages_str = NULL;
 	gchar *path;
 	GError *error = NULL;
+	GPtrArray *packages;
+	guint i;
 
 	/* not interesting to us */
 	if (transaction->priv->role != PK_ROLE_ENUM_UPDATE_PACKAGES &&
@@ -1121,14 +1183,28 @@ pk_transaction_write_prepared_file (PkTransaction *transaction)
 		return;
 	}
 
-	/* write filename */
+	/* get the existing prepared updates */
 	path = g_build_filename (LOCALSTATEDIR,
 				 "lib",
 				 "PackageKit",
 				 "prepared-update",
 				 NULL);
+	packages = pk_transaction_get_existing_prepared_updates (path);
+
+	/* add any new ones */
+	package_ids = transaction->priv->cached_package_ids;
+	for (i = 0; package_ids[i] != NULL; i++) {
+		if (!pk_transaction_array_str_exists (packages, package_ids[i])) {
+			g_ptr_array_add (packages,
+					 g_strdup (package_ids[i]));
+		}
+	}
+	g_ptr_array_add (packages, NULL);
+
+	/* write filename */
+	packages_str = g_strjoinv ("\n", (gchar **) packages->pdata);
 	ret = g_file_set_contents (path,
-				   pk_role_enum_to_string (transaction->priv->role),
+				   packages_str,
 				   -1,
 				   &error);
 	if (!ret) {
@@ -1136,6 +1212,7 @@ pk_transaction_write_prepared_file (PkTransaction *transaction)
 			   path, error->message);
 		g_error_free (error);
 	}
+	g_free (packages_str);
 	g_free (path);
 }
 
@@ -1751,7 +1828,7 @@ pk_transaction_transaction_cb (PkTransactionDb *tdb,
 				       transaction->priv->tid,
 				       PK_DBUS_INTERFACE_TRANSACTION,
 				       "Transaction",
-				       g_variant_new ("(osbsusus)",
+				       g_variant_new ("(osbuusus)",
 						      tid,
 						      timespec,
 						      succeeded,
@@ -2880,6 +2957,21 @@ pk_transaction_obtain_authorization (PkTransaction *transaction,
 
 	g_return_val_if_fail (priv->sender != NULL, FALSE);
 
+	/* we don't need to authenticate at all to just download packages */
+	if (pk_bitfield_contain (transaction->priv->cached_transaction_flags,
+				 PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD)) {
+		g_debug ("No authentication required for only-download");
+		ret = pk_transaction_commit (transaction);
+		if (!ret) {
+			g_set_error_literal (error,
+					     PK_TRANSACTION_ERROR,
+					     PK_TRANSACTION_ERROR_COMMIT_FAILED,
+					     "Could not commit to a transaction object");
+			pk_transaction_release_tid (transaction);
+			goto out;
+		}
+	}
+
 	/* we should always have subject */
 	if (priv->subject == NULL) {
 		g_set_error (error, PK_TRANSACTION_ERROR, PK_TRANSACTION_ERROR_REFUSED_BY_POLICY,
@@ -3029,6 +3121,18 @@ pk_transaction_get_role (PkTransaction *transaction)
 }
 
 /**
+ * pk_transaction_set_role:
+ **/
+static void
+pk_transaction_set_role (PkTransaction *transaction, PkRoleEnum role)
+{
+	transaction->priv->role = role;
+	pk_transaction_emit_property_changed (transaction,
+					      "Role",
+					      g_variant_new_uint32 (role));
+}
+
+/**
  * pk_transaction_dbus_return:
  **/
 static void
@@ -3065,7 +3169,6 @@ pk_transaction_accept_eula (PkTransaction *transaction,
 
 	g_return_if_fail (PK_IS_TRANSACTION (transaction));
 	g_return_if_fail (transaction->priv->tid != NULL);
-	transaction->priv->role = PK_ROLE_ENUM_ACCEPT_EULA;
 
 	g_variant_get (params, "(&s)",
 		       &eula_id);
@@ -3077,6 +3180,8 @@ pk_transaction_accept_eula (PkTransaction *transaction,
 		goto out;
 	}
 
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_ACCEPT_EULA);
+
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
 						   PK_ROLE_ENUM_ACCEPT_EULA,
@@ -3319,7 +3424,7 @@ pk_transaction_download_packages (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_package_ids = g_strdupv (package_ids);
 	transaction->priv->cached_directory = g_strdup (directory);
-	transaction->priv->role = PK_ROLE_ENUM_DOWNLOAD_PACKAGES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_DOWNLOAD_PACKAGES);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -3360,7 +3465,7 @@ pk_transaction_get_categories (PkTransaction *transaction,
 		goto out;
 	}
 
-	transaction->priv->role = PK_ROLE_ENUM_GET_CATEGORIES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_CATEGORIES);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -3434,7 +3539,7 @@ pk_transaction_get_depends (PkTransaction *transaction,
 	transaction->priv->cached_filters = filter;
 	transaction->priv->cached_package_ids = g_strdupv (package_ids);
 	transaction->priv->cached_force = recursive;
-	transaction->priv->role = PK_ROLE_ENUM_GET_DEPENDS;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_DEPENDS);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -3504,7 +3609,7 @@ pk_transaction_get_details (PkTransaction *transaction,
 
 	/* save so we can run later */
 	transaction->priv->cached_package_ids = g_strdupv (package_ids);
-	transaction->priv->role = PK_ROLE_ENUM_GET_DETAILS;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_DETAILS);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -3545,7 +3650,7 @@ pk_transaction_get_distro_upgrades (PkTransaction *transaction,
 	}
 
 	/* save so we can run later */
-	transaction->priv->role = PK_ROLE_ENUM_GET_DISTRO_UPGRADES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_DISTRO_UPGRADES);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -3613,7 +3718,7 @@ pk_transaction_get_files (PkTransaction *transaction,
 
 	/* save so we can run later */
 	transaction->priv->cached_package_ids = g_strdupv (package_ids);
-	transaction->priv->role = PK_ROLE_ENUM_GET_FILES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_FILES);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -3659,7 +3764,7 @@ pk_transaction_get_packages (PkTransaction *transaction,
 
 	/* save so we can run later */
 	transaction->priv->cached_filters = filter;
-	transaction->priv->role = PK_ROLE_ENUM_GET_PACKAGES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_PACKAGES);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -3692,7 +3797,7 @@ pk_transaction_get_old_transactions (PkTransaction *transaction,
 
 	g_debug ("GetOldTransactions method called");
 
-	transaction->priv->role = PK_ROLE_ENUM_GET_OLD_TRANSACTIONS;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_OLD_TRANSACTIONS);
 	pk_transaction_db_get_list (transaction->priv->transaction_db, number);
 	idle_id = g_idle_add ((GSourceFunc) pk_transaction_finished_idle_cb, transaction);
 	g_source_set_name_by_id (idle_id, "[PkTransaction] finished from get-old-transactions");
@@ -3731,7 +3836,7 @@ pk_transaction_get_repo_list (PkTransaction *transaction,
 
 	/* save so we can run later */
 	transaction->priv->cached_filters = filter;
-	transaction->priv->role = PK_ROLE_ENUM_GET_REPO_LIST;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_REPO_LIST);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -3806,7 +3911,7 @@ pk_transaction_get_requires (PkTransaction *transaction,
 	transaction->priv->cached_filters = filter;
 	transaction->priv->cached_package_ids = g_strdupv (package_ids);
 	transaction->priv->cached_force = recursive;
-	transaction->priv->role = PK_ROLE_ENUM_GET_REQUIRES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_REQUIRES);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -3875,7 +3980,7 @@ pk_transaction_get_update_detail (PkTransaction *transaction,
 
 	/* save so we can run later */
 	transaction->priv->cached_package_ids = g_strdupv (package_ids);
-	transaction->priv->role = PK_ROLE_ENUM_GET_UPDATE_DETAIL;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_UPDATE_DETAIL);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -4004,7 +4109,7 @@ pk_transaction_get_updates (PkTransaction *transaction,
 
 	/* save so we can run later */
 	transaction->priv->cached_filters = filter;
-	transaction->priv->role = PK_ROLE_ENUM_GET_UPDATES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_UPDATES);
 
 	/* try and reuse cache */
 	ret = pk_transaction_try_emit_cache (transaction);
@@ -4166,7 +4271,7 @@ pk_transaction_install_files (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_transaction_flags = transaction_flags;
 	transaction->priv->cached_full_paths = g_strdupv (full_paths);
-	transaction->priv->role = PK_ROLE_ENUM_INSTALL_FILES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_INSTALL_FILES);
 
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
@@ -4239,7 +4344,7 @@ pk_transaction_install_packages (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_transaction_flags = transaction_flags;
 	transaction->priv->cached_package_ids = g_strdupv (package_ids);
-	transaction->priv->role = PK_ROLE_ENUM_INSTALL_PACKAGES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_INSTALL_PACKAGES);
 
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
@@ -4309,7 +4414,7 @@ pk_transaction_install_signature (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_package_id = g_strdup (package_id);
 	transaction->priv->cached_key_id = g_strdup (key_id);
-	transaction->priv->role = PK_ROLE_ENUM_INSTALL_SIGNATURE;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_INSTALL_SIGNATURE);
 
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
@@ -4357,7 +4462,7 @@ pk_transaction_refresh_cache (PkTransaction *transaction,
 
 	/* save so we can run later */
 	transaction->priv->cached_force = force;
-	transaction->priv->role = PK_ROLE_ENUM_REFRESH_CACHE;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_REFRESH_CACHE);
 
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
@@ -4435,7 +4540,7 @@ pk_transaction_remove_packages (PkTransaction *transaction,
 	transaction->priv->cached_package_ids = g_strdupv (package_ids);
 	transaction->priv->cached_allow_deps = allow_deps;
 	transaction->priv->cached_autoremove = autoremove;
-	transaction->priv->role = PK_ROLE_ENUM_REMOVE_PACKAGES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_REMOVE_PACKAGES);
 
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
@@ -4491,7 +4596,7 @@ pk_transaction_repo_enable (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_repo_id = g_strdup (repo_id);
 	transaction->priv->cached_enabled = enabled;
-	transaction->priv->role = PK_ROLE_ENUM_REPO_ENABLE;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_REPO_ENABLE);
 
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
@@ -4550,7 +4655,7 @@ pk_transaction_repo_set_data (PkTransaction *transaction,
 	transaction->priv->cached_repo_id = g_strdup (repo_id);
 	transaction->priv->cached_parameter = g_strdup (parameter);
 	transaction->priv->cached_value = g_strdup (value);
-	transaction->priv->role = PK_ROLE_ENUM_REPO_SET_DATA;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_REPO_SET_DATA);
 
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
@@ -4630,7 +4735,7 @@ pk_transaction_resolve (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_package_ids = g_strdupv (packages);
 	transaction->priv->cached_filters = filter;
-	transaction->priv->role = PK_ROLE_ENUM_RESOLVE;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_RESOLVE);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -4687,7 +4792,7 @@ pk_transaction_search_details (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_filters = filter;
 	transaction->priv->cached_values = g_strdupv (values);
-	transaction->priv->role = PK_ROLE_ENUM_SEARCH_DETAILS;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_SEARCH_DETAILS);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -4754,7 +4859,7 @@ pk_transaction_search_files (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_filters = filter;
 	transaction->priv->cached_values = g_strdupv (values);
-	transaction->priv->role = PK_ROLE_ENUM_SEARCH_FILE;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_SEARCH_FILE);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -4821,7 +4926,7 @@ pk_transaction_search_groups (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_filters = filter;
 	transaction->priv->cached_values = g_strdupv (values);
-	transaction->priv->role = PK_ROLE_ENUM_SEARCH_GROUP;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_SEARCH_GROUP);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -4877,7 +4982,7 @@ pk_transaction_search_names (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_filters = filter;
 	transaction->priv->cached_values = g_strdupv (values);
-	transaction->priv->role = PK_ROLE_ENUM_SEARCH_NAME;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_SEARCH_NAME);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -5112,7 +5217,7 @@ pk_transaction_update_packages (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_transaction_flags = transaction_flags;
 	transaction->priv->cached_package_ids = g_strdupv (package_ids);
-	transaction->priv->role = PK_ROLE_ENUM_UPDATE_PACKAGES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_UPDATE_PACKAGES);
 
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
@@ -5165,7 +5270,7 @@ pk_transaction_update_system (PkTransaction *transaction,
 	}
 
 	transaction->priv->cached_transaction_flags = transaction_flags;
-	transaction->priv->role = PK_ROLE_ENUM_UPDATE_SYSTEM;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_UPDATE_SYSTEM);
 
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
@@ -5225,7 +5330,7 @@ pk_transaction_what_provides (PkTransaction *transaction,
 	transaction->priv->cached_filters = filter;
 	transaction->priv->cached_values = g_strdupv (values);
 	transaction->priv->cached_provides = provides;
-	transaction->priv->role = PK_ROLE_ENUM_WHAT_PROVIDES;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_WHAT_PROVIDES);
 
 	/* try to commit this */
 	ret = pk_transaction_commit (transaction);
@@ -5274,7 +5379,7 @@ pk_transaction_upgrade_system (PkTransaction *transaction,
 	/* save so we can run later */
 	transaction->priv->cached_value = g_strdup (distro_id);
 	transaction->priv->cached_provides = upgrade_kind;
-	transaction->priv->role = PK_ROLE_ENUM_UPGRADE_SYSTEM;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_UPGRADE_SYSTEM);
 
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
@@ -5319,7 +5424,7 @@ pk_transaction_repair_system (PkTransaction *transaction,
 
 	/* save so we can run later */
 	transaction->priv->cached_transaction_flags = transaction_flags;
-	transaction->priv->role = PK_ROLE_ENUM_REPAIR_SYSTEM;
+	pk_transaction_set_role (transaction, PK_ROLE_ENUM_REPAIR_SYSTEM);
 
 	/* try to get authorization */
 	ret = pk_transaction_obtain_authorization (transaction,
diff --git a/src/plugins/pk-plugin-clear-firmware-requests.c b/src/plugins/pk-plugin-clear-firmware-requests.c
index 8b4216a..f9326f4 100644
--- a/src/plugins/pk-plugin-clear-firmware-requests.c
+++ b/src/plugins/pk-plugin-clear-firmware-requests.c
@@ -51,6 +51,8 @@ pk_plugin_transaction_finished_end (PkPlugin *plugin,
 
 	/* clear the firmware requests directory */
 	filename = g_build_filename (LOCALSTATEDIR, "run", "PackageKit", "udev", NULL);
+	if (!g_file_test (filename, G_FILE_TEST_EXISTS))
+		goto out;
 	g_debug ("clearing udev firmware requests at %s", filename);
 	ret = pk_directory_remove_contents (filename);
 	if (!ret)