[gnome-software/jrocha/fix-install-queue: 8/8] Refactor save_install_queue
- From: Joaquim Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/jrocha/fix-install-queue: 8/8] Refactor save_install_queue
- Date: Fri, 16 Feb 2018 13:33:09 +0000 (UTC)
commit e7844ab2e0204c29e574300d006b62ffcae363ce
Author: Joaquim Rocha <jrocha endlessm com>
Date: Fri Feb 16 13:25:01 2018 +0100
Refactor save_install_queue
The save_install_queue can be made simpler by using the
gs_plugin_loader_get_pending function instead of using the pending apps
array directly.
This patch does that but a couple of cosmetic changes.
https://phabricator.endlessm.com/T21194
lib/gs-plugin-loader.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index c7b2a6d2..ec89d03c 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1768,26 +1768,19 @@ load_install_queue (GsPluginLoader *plugin_loader, GError **error)
static void
save_install_queue (GsPluginLoader *plugin_loader)
{
- GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
- GPtrArray *pending_apps;
- gboolean ret;
+ GsAppList *pending_apps = gs_plugin_loader_get_pending (plugin_loader);
g_autoptr(GError) error = NULL;
g_autoptr(GString) s = NULL;
g_autofree gchar *file = NULL;
s = g_string_new ("");
- pending_apps = priv->pending_apps;
- g_mutex_lock (&priv->pending_apps_mutex);
- for (guint i = 0; i < pending_apps->len; ++i) {
- const gchar *id = g_ptr_array_index (pending_apps, i);
- GsApp *app = gs_app_list_lookup (priv->global_cache, id);
-
- if (app != NULL && gs_app_get_state (app) == AS_APP_STATE_QUEUED_FOR_INSTALL) {
+ for (guint i = 0; i < gs_app_list_length (pending_apps); ++i) {
+ GsApp *app = gs_app_list_index (pending_apps, i);
+ if (gs_app_get_state (app) == AS_APP_STATE_QUEUED_FOR_INSTALL) {
g_string_append (s, gs_app_get_unique_id (app));
g_string_append_c (s, '\n');
}
}
- g_mutex_unlock (&priv->pending_apps_mutex);
/* save file */
file = g_build_filename (g_get_user_data_dir (),
@@ -1800,8 +1793,7 @@ save_install_queue (GsPluginLoader *plugin_loader)
return;
}
g_debug ("saving install queue to %s", file);
- ret = g_file_set_contents (file, s->str, (gssize) s->len, &error);
- if (!ret)
+ if (!g_file_set_contents (file, s->str, (gssize) s->len, &error))
g_warning ("failed to save install queue: %s", error->message);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]