After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 680760 - GFile: Add g_file_delete_async()
GFile: Add g_file_delete_async()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-07-28 20:04 UTC by Colin Walters
Modified: 2012-07-30 09:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GFile: Add g_file_delete_async() (11.22 KB, patch)
2012-07-28 20:04 UTC, Colin Walters
committed Details | Review

Description Colin Walters 2012-07-28 20:04:56 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.
Comment 1 Colin Walters 2012-07-28 20:04:59 UTC
Created attachment 219803 [details] [review]
GFile: Add g_file_delete_async()
Comment 2 Xavier Claessens 2012-07-29 07:36:31 UTC
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;
}
Comment 3 Colin Walters 2012-07-29 08:30:05 UTC
(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.
Comment 4 Matthias Clasen 2012-07-30 06:38:20 UTC
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
Comment 5 Colin Walters 2012-07-30 09:02:07 UTC
Attachment 219803 [details] pushed as 14a1c20 - GFile: Add g_file_delete_async()