GNOME Bugzilla – Bug 680760
GFile: Add g_file_delete_async()
Last modified: 2012-07-30 09:02:10 UTC
This looks like it was stubbed out but not implemented; the vtable entry dates to commit 3781343738de4abddf56982325a77bd70a98cd26 which is just alex's initial merge of gio into glib. I was working on some code that wants an asynchronous rm -rf equivalent, and so yeah, this is desirable.
Created attachment 219803 [details] [review] GFile: Add g_file_delete_async()
This is just async version of g_file_delete() which won't recursively delete your folder as "rm -rf" would do. Doc says: "If the file is a directory, it will only be deleted if it is empty." In telepathy we have this code we copied in most of our modules, I was pretty sure we proposed it upstream already but I couldn't find a gio bug for that... static gboolean haze_remove_directory (const gchar *path) { const gchar *child_path; GDir *dir = g_dir_open (path, 0, NULL); gboolean ret = TRUE; if (!dir) return FALSE; while (ret && (child_path = g_dir_read_name (dir))) { gchar *child_full_path = g_build_filename (path, child_path, NULL); if (g_file_test (child_full_path, G_FILE_TEST_IS_DIR)) { if (!haze_remove_directory (child_full_path)) ret = FALSE; } else { DEBUG ("deleting %s", child_full_path); if (g_unlink (child_full_path)) ret = FALSE; } g_free (child_full_path); } g_dir_close (dir); if (ret) { DEBUG ("deleting %s", path); ret = !g_rmdir (path); } return ret; }
(In reply to comment #2) > This is just async version of g_file_delete() which won't recursively delete > your folder as "rm -rf" would do. Doc says: "If the file is a directory, it > will only be deleted if it is empty." That's correct. See the associated blog entry: http://blog.verbum.org/2012/07/28/on-asynchronousevent-driven-programming-and-why-it-lies-at-the-heart-of-gtk-and-thus-gnome/ > In telepathy we have this code we copied in most of our modules, I was pretty > sure we proposed it upstream already but I couldn't find a gio bug for that... Yeah, it might make sense for GIO to have more stuff that's like Python's "shutil", but...one patch at a time.
Review of attachment 219803 [details] [review]: Looks good to me. The commit message could make it more clear that the function introduced here is _not_ recursive, e.g by adding ...is desirable as a building block for that or something of that nature
Attachment 219803 [details] pushed as 14a1c20 - GFile: Add g_file_delete_async()