[giggle] Add helper method for removing a directory recursively
- From: Javier Jardón <jjardon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [giggle] Add helper method for removing a directory recursively
- Date: Fri, 7 May 2010 03:33:21 +0000 (UTC)
commit cec4aeabe5d6ae24b25e992a7899ed233b3e1dcf
Author: Florian Müllner <florian muellner gmail com>
Date: Fri May 7 04:27:32 2010 +0200
Add helper method for removing a directory recursively
Credit goes to Paolo Bacchilega, who wrote this code for file-roller.
https://bugzilla.gnome.org/show_bug.cgi?id=608267
src/giggle-helpers.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/giggle-helpers.h | 2 +
2 files changed, 67 insertions(+), 0 deletions(-)
---
diff --git a/src/giggle-helpers.c b/src/giggle-helpers.c
index d5419ba..cd35ce0 100644
--- a/src/giggle-helpers.c
+++ b/src/giggle-helpers.c
@@ -212,3 +212,68 @@ giggle_open_file (GtkWidget *widget,
g_free (path);
g_free (uri);
}
+
+static gboolean
+delete_directory_recursive (GFile *dir, GError **error)
+{
+ gchar *uri;
+ GFileEnumerator *file_enum;
+ GFileInfo *info;
+ gboolean _failure = FALSE;
+
+ if (error != NULL)
+ *error = NULL;
+
+ file_enum = g_file_enumerate_children (dir,
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, error);
+
+ uri = g_file_get_uri (dir);
+ while (! _failure &&
+ (info = g_file_enumerator_next_file (file_enum, NULL, error))) {
+ gchar *child_uri;
+ GFile *child;
+
+ child_uri = g_build_filename (uri, g_file_info_get_name (info), NULL);
+ child = g_file_new_for_uri (child_uri);
+ g_free (child_uri);
+
+ switch (g_file_info_get_file_type (info)) {
+ case G_FILE_TYPE_DIRECTORY:
+ if (! delete_directory_recursive (child, error))
+ _failure = TRUE;
+ break;
+ default:
+ if (! g_file_delete (child, NULL, error))
+ _failure = TRUE;
+ break;
+ }
+
+ g_object_unref (child);
+ g_object_unref (info);
+ }
+ if (file_enum)
+ g_object_unref (file_enum);
+ g_free (uri);
+
+ if (! _failure && ! g_file_delete (dir, NULL, error))
+ _failure = TRUE;
+
+ return !_failure;
+}
+
+void
+giggle_remove_directory_recursive (const gchar *path)
+{
+ GFile *dir;
+ GError *error = NULL;
+
+ dir = g_file_new_for_path (path);
+ delete_directory_recursive (dir, &error);
+ if (error) {
+ g_warning ("Cannot delete %s: %s", path, error->message);
+ g_error_free (error);
+ }
+ g_object_unref (dir);
+}
diff --git a/src/giggle-helpers.h b/src/giggle-helpers.h
index c9df2e5..5d39ad9 100644
--- a/src/giggle-helpers.h
+++ b/src/giggle-helpers.h
@@ -43,6 +43,8 @@ void giggle_open_file (GtkWidget *wi
void giggle_error_dialog (GtkWindow *window,
GError *error);
+void giggle_remove_directory_recursive (const gchar *uri);
+
G_END_DECLS
#endif /* __GIGGLE_DUMMY_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]