[gnome-builder] app: reap legacy data at startup
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] app: reap legacy data at startup
- Date: Tue, 21 Nov 2017 08:36:22 +0000 (UTC)
commit e82bcf451349eae8bd5d4cef3f5ff27c8dcf320d
Author: Christian Hergert <chergert redhat com>
Date: Tue Nov 21 00:35:01 2017 -0800
app: reap legacy data at startup
When starting Builder, start reaping old data created by
legacy versions of Builder. Now that project data is in a
per-project directory, we can just wipe the project directory
when it is deleted.
However, we don't want to leave all this old data around, so
we need to reap it, might as well be now.
src/libide/application/ide-application.c | 89 +++++++++++++++++++++++++++---
1 files changed, 80 insertions(+), 9 deletions(-)
---
diff --git a/src/libide/application/ide-application.c b/src/libide/application/ide-application.c
index 20a70b4..9cc9a29 100644
--- a/src/libide/application/ide-application.c
+++ b/src/libide/application/ide-application.c
@@ -66,6 +66,15 @@
G_DEFINE_TYPE (IdeApplication, ide_application, DZL_TYPE_APPLICATION)
static GThread *main_thread;
+static const gchar *legacy_dirs[] = {
+ "buffers",
+ "builds",
+ "code-index",
+ "flatpak",
+ "install",
+ "tags",
+ NULL,
+};
void
_ide_application_set_mode (IdeApplication *self,
@@ -388,21 +397,83 @@ ide_application_register_settings (IdeApplication *self)
IDE_EXIT;
}
+static GFile *
+build_legacy_cache_directory (const gchar *name)
+{
+ return g_file_new_build_filename (g_get_user_cache_dir (),
+ ide_get_program_name (),
+ name,
+ NULL);
+}
+
+static void
+ide_application_reap_legacy_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ DzlDirectoryReaper *reaper = (DzlDirectoryReaper *)object;
+ g_autoptr(IdeApplication) self = user_data;
+ g_autoptr(GError) error = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (DZL_IS_DIRECTORY_REAPER (reaper));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (IDE_IS_APPLICATION (self));
+
+ if (!dzl_directory_reaper_execute_finish (reaper, result, &error))
+ {
+ g_warning ("Failure reaping legacy data: %s", error->message);
+ IDE_EXIT;
+ }
+
+ for (guint i = 0; legacy_dirs[i] != NULL; i++)
+ {
+ g_autoptr(GFile) directory = NULL;
+ const gchar *name = legacy_dirs[i];
+
+ directory = build_legacy_cache_directory (name);
+ g_file_delete_async (directory, G_PRIORITY_LOW, NULL, NULL, NULL);
+ }
+
+ IDE_EXIT;
+}
+
+/*
+ * _ide_application_reap_legacy:
+ *
+ * This is meant to remove a bunch of legacy directories we no longer use.
+ * Since it can take a while, we do it in the background at startup if we
+ * discover they are there.
+ */
static void
-_ide_application_init_reapers (IdeApplication *self)
+_ide_application_reap_legacy (IdeApplication *self)
{
g_autoptr(DzlDirectoryReaper) reaper = NULL;
- g_autoptr(GFile) buffers = NULL;
+
+ IDE_ENTRY;
g_assert (IDE_IS_APPLICATION (self));
reaper = dzl_directory_reaper_new ();
- buffers = g_file_new_build_filename (g_get_user_cache_dir (),
- ide_get_program_name (),
- "buffers",
- NULL);
- dzl_directory_reaper_add_directory (reaper, buffers, G_TIME_SPAN_HOUR);
- ide_application_add_reaper (self, reaper);
+
+ /* Cleanup a number of old directories no longer used */
+ for (guint i = 0; legacy_dirs[i] != NULL; i++)
+ {
+ g_autoptr(GFile) directory = NULL;
+ const gchar *name = legacy_dirs[i];
+
+ directory = build_legacy_cache_directory (name);
+ dzl_directory_reaper_add_directory (reaper, directory, 0);
+ }
+
+ /* Do this asynchronously so we don't block the program at shutdown. */
+ dzl_directory_reaper_execute_async (reaper,
+ NULL,
+ ide_application_reap_legacy_cb,
+ g_object_ref (self));
+
+ IDE_EXIT;
}
static void
@@ -435,7 +506,7 @@ ide_application_startup (GApplication *application)
ide_application_actions_init (self);
_ide_application_init_shortcuts (self);
_ide_application_init_color (self);
- _ide_application_init_reapers (self);
+ _ide_application_reap_legacy (self);
modeline_parser_init ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]