[gimp] app: rename gimp_rec_rm() to gimp_file_delete_recursive()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: rename gimp_rec_rm() to gimp_file_delete_recursive()
- Date: Fri, 31 May 2019 15:13:18 +0000 (UTC)
commit 317b09c90f7014d3171dbe971641c2ba4f08cbae
Author: Michael Natterer <mitch gimp org>
Date: Fri May 31 17:11:50 2019 +0200
app: rename gimp_rec_rm() to gimp_file_delete_recursive()
and move it to the right place in gimp-utils.[ch].
app/core/gimp-utils.c | 131 ++++++++++++++++++++--------------------
app/core/gimp-utils.h | 4 +-
app/core/gimpextensionmanager.c | 2 +-
app/file-data/file-data-gex.c | 12 +++-
4 files changed, 78 insertions(+), 71 deletions(-)
---
diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c
index 5265c0b8ed..8f1a29e42d 100644
--- a/app/core/gimp-utils.c
+++ b/app/core/gimp-utils.c
@@ -772,6 +772,72 @@ gimp_file_with_new_extension (GFile *file,
return ret;
}
+
+/**
+ * gimp_file_delete_recursive:
+ * @file: #GFile to delete from file system.
+ * @error:
+ *
+ * Delete @file. If file is a directory, it will delete its children as
+ * well recursively. It will not follow symlinks so you won't end up in
+ * infinite loops, not will you be at risk of deleting your whole file
+ * system (unless you pass the root of course!).
+ * Such function unfortunately does not exist in glib, which only allows
+ * to delete single files or empty directories by default.
+ *
+ * Returns: #TRUE if @file was successfully deleted and all its
+ * children, #FALSE otherwise with @error filled.
+ */
+gboolean
+gimp_file_delete_recursive (GFile *file,
+ GError **error)
+{
+ gboolean success = TRUE;
+
+ if (g_file_query_exists (file, NULL))
+ {
+ if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL) == G_FILE_TYPE_DIRECTORY)
+ {
+ GFileEnumerator *enumerator;
+
+ enumerator = g_file_enumerate_children (file,
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
+ G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NONE,
+ NULL, NULL);
+ if (enumerator)
+ {
+ GFileInfo *info;
+
+ while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)))
+ {
+ GFile *child;
+
+ child = g_file_enumerator_get_child (enumerator, info);
+ g_object_unref (info);
+
+ if (! gimp_file_delete_recursive (child, error))
+ success = FALSE;
+
+ g_object_unref (child);
+ if (! success)
+ break;
+ }
+
+ g_object_unref (enumerator);
+ }
+ }
+
+ if (success)
+ /* Non-directory or empty directory. */
+ success = g_file_delete (file, NULL, error);
+ }
+
+ return success;
+}
+
gchar *
gimp_data_input_stream_read_line_always (GDataInputStream *stream,
gsize *length,
@@ -928,68 +994,3 @@ gimp_create_image_from_buffer (Gimp *gimp,
return image;
}
-
-/**
- * gimp_rec_rm:
- * @file: #GFile to delete from file system.
- * @error:
- *
- * Delete @file. If file is a directory, it will delete its children as
- * well recursively. It will not follow symlinks so you won't end up in
- * infinite loops, not will you be at risk of deleting your whole file
- * system (unless you pass the root of course!).
- * Such function unfortunately does not exist in glib, which only allows
- * to delete single files or empty directories by default.
- *
- * Returns: #TRUE if @file was successfully deleted and all its
- * children, #FALSE otherwise with @error filled.
- */
-gboolean
-gimp_rec_rm (GFile *file,
- GError **error)
-{
- gboolean success = TRUE;
-
- if (g_file_query_exists (file, NULL))
- {
- if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL) == G_FILE_TYPE_DIRECTORY)
- {
- GFileEnumerator *enumerator;
-
- enumerator = g_file_enumerate_children (file,
- G_FILE_ATTRIBUTE_STANDARD_NAME ","
- G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
- G_FILE_ATTRIBUTE_TIME_MODIFIED,
- G_FILE_QUERY_INFO_NONE,
- NULL, NULL);
- if (enumerator)
- {
- GFileInfo *info;
-
- while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)))
- {
- GFile *child;
-
- child = g_file_enumerator_get_child (enumerator, info);
- g_object_unref (info);
-
- if (! gimp_rec_rm (child, error))
- success = FALSE;
-
- g_object_unref (child);
- if (! success)
- break;
- }
-
- g_object_unref (enumerator);
- }
- }
-
- if (success)
- /* Non-directory or empty directory. */
- success = g_file_delete (file, NULL, error);
- }
-
- return success;
-}
diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h
index 726370afcd..172f2ad2e0 100644
--- a/app/core/gimp-utils.h
+++ b/app/core/gimp-utils.h
@@ -84,6 +84,8 @@ gboolean gimp_file_is_executable (GFile *file);
gchar * gimp_file_get_extension (GFile *file);
GFile * gimp_file_with_new_extension (GFile *file,
GFile *ext_file);
+gboolean gimp_file_delete_recursive (GFile *file,
+ GError **error);
gchar * gimp_data_input_stream_read_line_always (GDataInputStream *stream,
gsize *length,
@@ -105,7 +107,5 @@ GimpImage * gimp_create_image_from_buffer (Gimp *gimp,
GeglBuffer *buffer,
const gchar *image_name);
-gboolean gimp_rec_rm (GFile *file,
- GError **error);
#endif /* __APP_GIMP_UTILS_H__ */
diff --git a/app/core/gimpextensionmanager.c b/app/core/gimpextensionmanager.c
index 118966919b..4bfbdce48c 100644
--- a/app/core/gimpextensionmanager.c
+++ b/app/core/gimpextensionmanager.c
@@ -414,7 +414,7 @@ gimp_extension_manager_finalize (GObject *object)
GFile *file;
file = g_file_new_for_path (gimp_extension_get_path (iter->data));
- if (! gimp_rec_rm (file, &error))
+ if (! gimp_file_delete_recursive (file, &error))
g_warning ("%s: %s\n", G_STRFUNC, error->message);
g_object_unref (file);
}
diff --git a/app/file-data/file-data-gex.c b/app/file-data/file-data-gex.c
index efccb5d496..9ac22fd9ad 100644
--- a/app/file-data/file-data-gex.c
+++ b/app/file-data/file-data-gex.c
@@ -512,14 +512,17 @@ file_gex_load_invoker (GimpProcedure *procedure,
success = file_gex_validate (file, &appdata, error);
if (success)
- ext_dir = file_gex_decompress (file, (gchar *) as_app_get_id (appdata), error);
+ ext_dir = file_gex_decompress (file, (gchar *) as_app_get_id (appdata),
+ error);
+
if (ext_dir)
{
GimpExtension *extension;
GError *rm_error = NULL;
extension = gimp_extension_new (ext_dir, TRUE);
- success = gimp_extension_manager_install (gimp->extension_manager, extension, error);
+ success = gimp_extension_manager_install (gimp->extension_manager,
+ extension, error);
if (! success)
{
@@ -528,13 +531,16 @@ file_gex_load_invoker (GimpProcedure *procedure,
g_object_unref (extension);
file = g_file_new_for_path (ext_dir);
- if (! gimp_rec_rm (file, &rm_error))
+
+ if (! gimp_file_delete_recursive (file, &rm_error))
{
g_warning ("%s: %s\n", G_STRFUNC, rm_error->message);
g_error_free (rm_error);
}
+
g_object_unref (file);
}
+
g_free (ext_dir);
}
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]