[gnome-software/jrocha/fix-install-queue: 4/4] Fix updating the installation queue on disk
- From: Joaquim Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/jrocha/fix-install-queue: 4/4] Fix updating the installation queue on disk
- Date: Mon, 19 Feb 2018 09:53:48 +0000 (UTC)
commit 3c632ee14db008a36f43e4eaa6a67f5c71a558b8
Author: Joaquim Rocha <jrocha endlessm com>
Date: Fri Feb 16 22:04:30 2018 +0100
Fix updating the installation queue on disk
When an app is removed from the installation queue, it was not updating
the corresponding file on disk. So if an app was uninstalled, the next
time GNOME Software loaded the pending apps, the list would still
contain that previously uninstalled application.
This patch ensures that when an app is removed from the pending apps
queue in memory, the queue is also saved on disk.
lib/gs-plugin-loader.c | 78 ++++++++++++++++++++++++++++----------------------
1 file changed, 43 insertions(+), 35 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index ca624bee..b32caa9b 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1695,6 +1695,40 @@ gs_plugin_loader_pending_apps_add (GsPluginLoader *plugin_loader,
g_idle_add (emit_pending_apps_idle, g_object_ref (plugin_loader));
}
+static void
+save_install_queue (GsPluginLoader *plugin_loader)
+{
+ GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+ gboolean ret;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GString) s = NULL;
+ g_autofree gchar *file = NULL;
+
+ s = g_string_new ("");
+ g_mutex_lock (&priv->pending_apps_mutex);
+ for (guint i = 0; i < gs_app_list_length (priv->pending_apps); ++i) {
+ GsApp *app = gs_app_list_index (priv->pending_apps, i);
+ 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 (),
+ "gnome-software",
+ "install-queue",
+ NULL);
+ if (!gs_mkdir_parent (file, &error)) {
+ g_warning ("failed to create dir for %s: %s",
+ file, error->message);
+ return;
+ }
+ g_debug ("saving install queue to %s", file);
+ ret = g_file_set_contents (file, s->str, (gssize) s->len, &error);
+ if (!ret)
+ g_warning ("failed to save install queue: %s", error->message);
+}
+
static void
gs_plugin_loader_pending_apps_remove (GsPluginLoader *plugin_loader,
GsPluginLoaderHelper *helper)
@@ -1702,11 +1736,15 @@ gs_plugin_loader_pending_apps_remove (GsPluginLoader *plugin_loader,
GsAppList *list = gs_plugin_job_get_list (helper->plugin_job);
GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->pending_apps_mutex);
+ gboolean save_queue = FALSE;
g_assert (gs_app_list_length (list) > 0);
for (guint i = 0; i < gs_app_list_length (list); i++) {
GsApp *app = gs_app_list_index (list, i);
- gs_app_list_remove (priv->pending_apps, app);
+ if (gs_app_get_state (app) != AS_APP_STATE_QUEUED_FOR_INSTALL) {
+ save_queue = TRUE;
+ gs_app_list_remove (priv->pending_apps, app);
+ }
/* check the app is not still in an action helper */
switch (gs_app_get_state (app)) {
@@ -1722,6 +1760,10 @@ gs_plugin_loader_pending_apps_remove (GsPluginLoader *plugin_loader,
}
}
+ if (save_queue) {
+ g_clear_pointer (&locker, g_mutex_locker_free);
+ save_install_queue (plugin_loader);
+ }
g_idle_add (emit_pending_apps_idle, g_object_ref (plugin_loader));
}
@@ -1766,40 +1808,6 @@ load_install_queue (GsPluginLoader *plugin_loader, GError **error)
return TRUE;
}
-static void
-save_install_queue (GsPluginLoader *plugin_loader)
-{
- GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
- gboolean ret;
- g_autoptr(GError) error = NULL;
- g_autoptr(GString) s = NULL;
- g_autofree gchar *file = NULL;
-
- s = g_string_new ("");
- g_mutex_lock (&priv->pending_apps_mutex);
- for (guint i = 0; i < gs_app_list_length (priv->pending_apps); ++i) {
- GsApp *app = gs_app_list_index (priv->pending_apps, i);
- 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 (),
- "gnome-software",
- "install-queue",
- NULL);
- if (!gs_mkdir_parent (file, &error)) {
- g_warning ("failed to create dir for %s: %s",
- file, error->message);
- return;
- }
- g_debug ("saving install queue to %s", file);
- ret = g_file_set_contents (file, s->str, (gssize) s->len, &error);
- if (!ret)
- g_warning ("failed to save install queue: %s", error->message);
-}
-
static void
add_app_to_install_queue (GsPluginLoader *plugin_loader, GsApp *app)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]