[gnome-builder] Revert "beautifier-plugin: use per project Builder cache dir"
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] Revert "beautifier-plugin: use per project Builder cache dir"
- Date: Thu, 25 Jan 2018 00:50:27 +0000 (UTC)
commit 9b78cdbf95fd277e6c7f8b304a5cfe65c0855399
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 24 16:49:04 2018 -0800
Revert "beautifier-plugin: use per project Builder cache dir"
This reverts commit c5f8e0557d77e03d1032f02a17c6659e7a6d3a88.
src/plugins/beautifier/gb-beautifier-config.c | 70 +++++++-------
.../beautifier/gb-beautifier-editor-addin.c | 54 ++---------
src/plugins/beautifier/gb-beautifier-helper.c | 106 ++++++++++++++-------
src/plugins/beautifier/gb-beautifier-process.c | 12 +--
4 files changed, 118 insertions(+), 124 deletions(-)
---
diff --git a/src/plugins/beautifier/gb-beautifier-config.c b/src/plugins/beautifier/gb-beautifier-config.c
index cfd4a1731..6fab6c5fc 100644
--- a/src/plugins/beautifier/gb-beautifier-config.c
+++ b/src/plugins/beautifier/gb-beautifier-config.c
@@ -133,7 +133,7 @@ copy_to_tmp_file (GbBeautifierEditorAddin *self,
g_assert (!dzl_str_empty0 (tmp_dir));
g_assert (!dzl_str_empty0 (source_path));
- tmp_path = g_build_filename (tmp_dir, "XXXXXX.txt", NULL);
+ tmp_path = g_build_filename (tmp_dir, "gnome-builder-beautifier-XXXXXX.txt", NULL);
if (-1 != (fd = g_mkstemp (tmp_path)))
{
close (fd);
@@ -595,6 +595,8 @@ get_entries_worker (GTask *task,
GCancellable *cancellable)
{
GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)source_object;
+ g_autoptr (GError) error = NULL;
+ IdeContext *context;
IdeProject *project;
IdeVcs *vcs;
GArray *entries;
@@ -611,13 +613,14 @@ get_entries_worker (GTask *task,
g_assert (G_IS_TASK (task));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
- if (self->context == NULL)
+ if (self->tmp_dir == NULL)
{
- g_task_return_new_error (task,
- G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Failed to initialized the Beautifier plugin, no IdeContext ready");
- return;
+ if (NULL == (self->tmp_dir = g_dir_make_tmp ("gnome-builder-beautifier-XXXXXX", &error)))
+ {
+ g_task_return_error (task, g_steal_pointer (&error));
+ return;
+ }
+
}
entries = g_array_new (TRUE, TRUE, sizeof (GbBeautifierConfigEntry));
@@ -635,34 +638,37 @@ get_entries_worker (GTask *task,
g_clear_pointer (&map, g_array_unref);
/* Project wide config */
- if (NULL != (project = ide_context_get_project (self->context)))
+ if (NULL != (context = self->context))
{
- project_name = ide_project_get_name (project);
- if (dzl_str_equal0 (project_name, "Builder"))
+ if (NULL != (project = ide_context_get_project (context)))
{
- configdir = g_strdup ("resource:///org/gnome/builder/plugins/beautifier_plugin/self/");
- map = gb_beautifier_config_get_map (self, configdir);
- add_entries_from_base_path (self, configdir, entries, map, &ret_has_default);
- has_default |= ret_has_default;
- g_clear_pointer (&configdir, g_free);
+ project_name = ide_project_get_name (project);
+ if (dzl_str_equal0 (project_name, "Builder"))
+ {
+ configdir = g_strdup ("resource:///org/gnome/builder/plugins/beautifier_plugin/self/");
+ map = gb_beautifier_config_get_map (self, configdir);
+ add_entries_from_base_path (self, configdir, entries, map, &ret_has_default);
+ has_default |= ret_has_default;
+ g_clear_pointer (&configdir, g_free);
- g_clear_pointer (&map, g_array_unref);
- }
- else if (NULL != (vcs = ide_context_get_vcs (self->context)))
- {
- GFile *workdir;
- g_autofree gchar *workdir_path = NULL;
-
- workdir = ide_vcs_get_working_directory (vcs);
- workdir_path = g_file_get_path (workdir);
- project_config_path = g_build_filename (workdir_path,
- ".beautifier",
- NULL);
- map = gb_beautifier_config_get_map (self, project_config_path);
- add_entries_from_base_path (self, project_config_path, entries, map, &ret_has_default);
- has_default |= ret_has_default;
-
- g_clear_pointer (&map, g_array_unref);
+ g_clear_pointer (&map, g_array_unref);
+ }
+ else if (NULL != (vcs = ide_context_get_vcs (context)))
+ {
+ GFile *workdir;
+ g_autofree gchar *workdir_path = NULL;
+
+ workdir = ide_vcs_get_working_directory (vcs);
+ workdir_path = g_file_get_path (workdir);
+ project_config_path = g_build_filename (workdir_path,
+ ".beautifier",
+ NULL);
+ map = gb_beautifier_config_get_map (self, project_config_path);
+ add_entries_from_base_path (self, project_config_path, entries, map, &ret_has_default);
+ has_default |= ret_has_default;
+
+ g_clear_pointer (&map, g_array_unref);
+ }
}
}
diff --git a/src/plugins/beautifier/gb-beautifier-editor-addin.c
b/src/plugins/beautifier/gb-beautifier-editor-addin.c
index 776509c5e..5319ddbe7 100644
--- a/src/plugins/beautifier/gb-beautifier-editor-addin.c
+++ b/src/plugins/beautifier/gb-beautifier-editor-addin.c
@@ -354,9 +354,9 @@ add_shortcut_window_entry (GbBeautifierEditorAddin *self)
}
static void
-gb_beautifier_editor_addin_async_cb (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
+get_entries_async_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
{
g_autoptr(GbBeautifierEditorAddin) self = (GbBeautifierEditorAddin *)object;
GbBeautifierEntriesResult *ret;
@@ -386,43 +386,12 @@ gb_beautifier_editor_addin_async_cb (GObject *object,
add_shortcut_window_entry (self);
}
-static void
-gb_beautifier_editor_addin_reap_cb (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
-{
- DzlDirectoryReaper *reaper = (DzlDirectoryReaper *)object;
- g_autoptr(GbBeautifierEditorAddin) self = user_data;
- g_autoptr(GError) error = NULL;
-
- g_assert (DZL_IS_DIRECTORY_REAPER (reaper));
- g_assert (G_IS_ASYNC_RESULT (result));
- g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
-
- if (!dzl_directory_reaper_execute_finish (reaper, result, &error))
- g_warning ("Failed to reap old beautifier data: %s", error->message);
-
- if (g_mkdir_with_parents (self->tmp_dir, 0750) != 0)
- {
- g_warning ("Failed to initialized the Beautifier plugin, can't write the temporary directory");
- return;
- }
-
- gb_beautifier_config_get_entries_async (self,
- &self->has_default,
- gb_beautifier_editor_addin_async_cb,
- NULL,
- g_object_ref (self));
-}
-
static void
gb_beautifier_editor_addin_load (IdeEditorAddin *addin,
IdeEditorPerspective *editor)
{
GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)addin;
IdeWorkbench *workbench;
- g_autoptr(DzlDirectoryReaper) reaper = NULL;
- g_autoptr (GFile) tmp_file = NULL;
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
g_assert (IDE_IS_EDITOR_PERSPECTIVE (editor));
@@ -432,18 +401,11 @@ gb_beautifier_editor_addin_load (IdeEditorAddin *addin,
self->context = ide_workbench_get_context (workbench);
ide_object_set_context (IDE_OBJECT (self), self->context);
- if (self->tmp_dir == NULL)
- self->tmp_dir = ide_context_cache_filename (self->context, "beautifier", NULL);
-
- /* Cleanup old beautifier cache directory */
- reaper = dzl_directory_reaper_new ();
- tmp_file = g_file_new_for_path (self->tmp_dir);
- dzl_directory_reaper_add_directory (reaper, tmp_file, 0);
-
- dzl_directory_reaper_execute_async (reaper,
- NULL,
- gb_beautifier_editor_addin_reap_cb,
- g_object_ref (self));
+ gb_beautifier_config_get_entries_async (self,
+ &self->has_default,
+ get_entries_async_cb,
+ NULL,
+ g_object_ref (self));
}
static void
diff --git a/src/plugins/beautifier/gb-beautifier-helper.c b/src/plugins/beautifier/gb-beautifier-helper.c
index ae1e13f3c..1406ef3b2 100644
--- a/src/plugins/beautifier/gb-beautifier-helper.c
+++ b/src/plugins/beautifier/gb-beautifier-helper.c
@@ -28,6 +28,14 @@
#include "gb-beautifier-helper.h"
#include "gb-beautifier-private.h"
+typedef struct
+{
+ GbBeautifierEditorAddin *self;
+ GFile *file;
+ GFileIOStream *stream;
+ gsize len;
+} SaveTmpState;
+
static gboolean
check_path_is_in_tmp_dir (const gchar *path,
const gchar *tmp_dir)
@@ -42,16 +50,20 @@ void
gb_beautifier_helper_remove_temp_for_path (GbBeautifierEditorAddin *self,
const gchar *path)
{
+ const gchar *tmp_dir;
+
g_assert (path != NULL);
- if (check_path_is_in_tmp_dir (path, self->tmp_dir))
+ tmp_dir = g_get_tmp_dir ();
+
+ if (check_path_is_in_tmp_dir (path, tmp_dir))
g_unlink (path);
else
{
ide_object_warning (self,
/* translators: %s and %s are replaced with the temporary dir and the file path */
_("Beautifier plugin: blocked attempt to remove a file outside of the “%s”
temporary directory: “%s”"),
- self->tmp_dir,
+ tmp_dir,
path);
return;
}
@@ -61,20 +73,22 @@ void
gb_beautifier_helper_remove_temp_for_file (GbBeautifierEditorAddin *self,
GFile *file)
{
+ const gchar *tmp_dir;
g_autofree gchar *path = NULL;
g_assert (G_IS_FILE (file));
+ tmp_dir = g_get_tmp_dir ();
path = g_file_get_path (file);
- if (check_path_is_in_tmp_dir (path, self->tmp_dir))
+ if (check_path_is_in_tmp_dir (path, tmp_dir))
g_file_delete (file, NULL, NULL);
else
{
ide_object_warning (self,
/* translators: %s and %s are replaced with the temporary dir and the file path */
_("Beautifier plugin: blocked attempt to remove a file outside of the “%s”
temporary directory: “%s”"),
- self->tmp_dir,
+ tmp_dir,
path);
return;
}
@@ -86,23 +100,25 @@ gb_beautifier_helper_config_entry_remove_temp_files (GbBeautifierEditorAddin *se
{
GbBeautifierCommandArg *arg;
g_autofree gchar *config_path = NULL;
+ const gchar *tmp_dir;
g_assert (config_entry != NULL);
+ tmp_dir = g_get_tmp_dir ();
if (config_entry->is_config_file_temp)
{
if (G_IS_FILE (config_entry->config_file))
{
config_path = g_file_get_path (config_entry->config_file);
- if (check_path_is_in_tmp_dir (config_path, self->tmp_dir))
+ if (check_path_is_in_tmp_dir (config_path, tmp_dir))
g_file_delete (config_entry->config_file, NULL, NULL);
else
{
ide_object_warning (self,
/* translators: %s and %s are replaced with the temporary dir and the file
path */
_("Beautifier plugin: blocked attempt to remove a file outside of the “%s”
temporary directory: “%s”"),
- self->tmp_dir,
+ tmp_dir,
config_path);
return;
}
@@ -116,13 +132,13 @@ gb_beautifier_helper_config_entry_remove_temp_files (GbBeautifierEditorAddin *se
arg = &g_array_index (config_entry->command_args, GbBeautifierCommandArg, i);
if (arg->is_temp && !dzl_str_empty0 (arg->str))
{
- if (check_path_is_in_tmp_dir (arg->str, self->tmp_dir))
+ if (check_path_is_in_tmp_dir (arg->str, tmp_dir))
g_unlink (arg->str);
else
{
ide_object_warning (self,
_("Beautifier plugin: blocked attempt to remove a file outside of the
“%s” temporary directory: “%s”"),
- self->tmp_dir,
+ tmp_dir,
arg->str);
return;
}
@@ -131,26 +147,43 @@ gb_beautifier_helper_config_entry_remove_temp_files (GbBeautifierEditorAddin *se
}
}
+static void
+save_tmp_state_free (gpointer data)
+{
+ SaveTmpState *state = (SaveTmpState *)data;
+
+ g_assert (data != NULL);
+
+ if (!g_io_stream_is_closed ((GIOStream *)state->stream))
+ g_io_stream_close ((GIOStream *)state->stream, NULL, NULL);
+
+ g_clear_object (&state->file);
+
+ g_slice_free (SaveTmpState, state);
+}
+
static void
gb_beautifier_helper_create_tmp_file_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- g_autoptr (GFile) file = (GFile *)object;
+ GOutputStream *output_stream = (GOutputStream *)object;
g_autoptr(GError) error = NULL;
g_autoptr(GTask) task = (GTask *)user_data;
+ SaveTmpState *state;
+ gsize count;
- g_assert (G_IS_FILE (file));
+ g_assert (G_IS_OUTPUT_STREAM (output_stream));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (G_IS_TASK (task));
- if (!g_file_replace_contents_finish (file, result, NULL, &error))
+ state = (SaveTmpState *)g_task_get_task_data (task);
+ if (!g_output_stream_write_all_finish (output_stream, result, &count, &error))
g_task_return_error (task, g_steal_pointer (&error));
-
- if (g_task_return_error_if_cancelled (task))
- g_file_delete (file, NULL, NULL);
+ else if (g_task_return_error_if_cancelled (task))
+ g_file_delete (state->file, NULL, NULL);
else
- g_task_return_pointer (task, g_steal_pointer (&file), g_object_unref);
+ g_task_return_pointer (task, g_steal_pointer (&state->file), g_object_unref);
}
void
@@ -160,10 +193,12 @@ gb_beautifier_helper_create_tmp_file_async (GbBeautifierEditorAddin *self,
GCancellable *cancellable,
gpointer user_data)
{
+ SaveTmpState *state;
+ GFile *file = NULL;
+ GFileIOStream *stream;
+ GOutputStream *output_stream;
g_autoptr(GTask) task = NULL;
- g_autofree gchar *tmp_path = NULL;
- GFile *file;
- gint fd;
+ g_autoptr(GError) error = NULL;
g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
g_assert (!dzl_str_empty0 (text));
@@ -172,29 +207,28 @@ gb_beautifier_helper_create_tmp_file_async (GbBeautifierEditorAddin *self,
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, gb_beautifier_helper_create_tmp_file_async);
+ state = g_slice_new0 (SaveTmpState);
+ state->self = self;
+ g_task_set_task_data (task, state, save_tmp_state_free);
- tmp_path = g_build_filename (self->tmp_dir, "XXXXXX.txt", NULL);
- if (-1 == (fd = g_mkstemp (tmp_path)))
+ if (NULL == (file = g_file_new_tmp ("gnome-builder-beautifier-XXXXXX.txt", &stream, &error)))
{
- g_task_return_new_error (task,
- G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Failed to create temporary file for the Beautifier plugin");
+ g_task_return_error (task, g_steal_pointer (&error));
return;
}
- g_close (fd, NULL);
- file = g_file_new_for_path (tmp_path);
-
- g_file_replace_contents_async (file,
- text,
- strlen (text),
- NULL,
- FALSE,
- G_FILE_CREATE_REPLACE_DESTINATION,
- NULL,
- gb_beautifier_helper_create_tmp_file_cb,
- g_steal_pointer (&task));
+ state->file = file;
+ state->stream = stream;
+ state->len = strlen (text);
+
+ output_stream = g_io_stream_get_output_stream ((GIOStream *)stream);
+ g_output_stream_write_all_async (output_stream,
+ text,
+ state->len,
+ G_PRIORITY_DEFAULT,
+ cancellable,
+ gb_beautifier_helper_create_tmp_file_cb,
+ g_steal_pointer (&task));
}
GFile *
diff --git a/src/plugins/beautifier/gb-beautifier-process.c b/src/plugins/beautifier/gb-beautifier-process.c
index 9b8b789d1..218836056 100644
--- a/src/plugins/beautifier/gb-beautifier-process.c
+++ b/src/plugins/beautifier/gb-beautifier-process.c
@@ -166,16 +166,8 @@ gb_beautifier_process_create_for_clang_format (GbBeautifierEditorAddin *self,
g_assert (!dzl_str_empty0 (src_path));
g_assert (!dzl_str_empty0 (state->lang_id));
- tmp_workdir = g_build_filename (self->tmp_dir, "clang-XXXXXX.txt", NULL);
- if (g_mkdtemp (tmp_workdir) == NULL)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Failed to create temporary directory for the Beautifier plugin");
-
- return NULL;
- }
+ if (NULL == (tmp_workdir = g_dir_make_tmp ("gnome-builder-beautify-XXXXXX", error)))
+ return NULL;
state->tmp_workdir_file = g_file_new_for_path (tmp_workdir);
tmp_config_path = g_build_filename (tmp_workdir,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]