[glib/wip/oholy/trash-recursion] gio-tool-trash: Prevent recursion to speed up emptying trash
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/oholy/trash-recursion] gio-tool-trash: Prevent recursion to speed up emptying trash
- Date: Wed, 16 Sep 2020 13:35:23 +0000 (UTC)
commit f2b6750d7dd981883ef822e15e0f7cdc1e6141c2
Author: Ondrej Holy <oholy redhat com>
Date: Wed Sep 16 15:22:46 2020 +0200
gio-tool-trash: Prevent recursion to speed up emptying trash
Emptying trash over `gio trash` is a bit slow in comparison to plain
`rm -r`. On my system, it took about 3 min to empty the trash with a
folder containing 600 000 files, which is not ideal as `rm -r` call
took just a few seconds. I found that `g_file_delete` is implemented
differently for locations provided by the trash backend. The trash
backend prevents modifications of trashed content thus the delete
operation is allowed only for the top-level files and folders. So it
is not necessary to recursive delete all files as the permission
denied error is returned anyway. Let's call `g_file_delete` only for
top-level items, which reduces the time necessary for emptying trash
from minutes to seconds...
See: https://gitlab.gnome.org/GNOME/nautilus/-/issues/1589
gio/gio-tool-trash.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/gio/gio-tool-trash.c b/gio/gio-tool-trash.c
index 4f9e3668a..924b94fea 100644
--- a/gio/gio-tool-trash.c
+++ b/gio/gio-tool-trash.c
@@ -53,7 +53,14 @@ delete_trash_file (GFile *file, gboolean del_file, gboolean del_children)
while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
{
child = g_file_get_child (file, g_file_info_get_name (info));
- delete_trash_file (child, TRUE, g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY);
+
+ /* The g_file_delete operation works differently for locations
+ * provided by the trash backend as it prevents modifications of
+ * trashed items. For that reason, it is enough to call
+ * g_file_delete on top-level items only.
+ */
+ delete_trash_file (child, TRUE, FALSE);
+
g_object_unref (child);
g_object_unref (info);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]