summaryrefslogtreecommitdiff
path: root/programs
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2012-11-25 00:43:15 -0500
committerMatthias Clasen <mclasen@redhat.com>2012-11-25 00:44:15 -0500
commit09c8be942506999490a0df74d4bcfa52de58a644 (patch)
tree1e3ba346ace94c72361f72aa56e8958b069d5155 /programs
parent5fe24e3a42164b20795d653d4bb00316cedba3ab (diff)
downloadgvfs-09c8be942506999490a0df74d4bcfa52de58a644.tar.gz
Add a cmdline way to empty the trash
Support gvfs-trash --empty to empty the trash.
Diffstat (limited to 'programs')
-rw-r--r--programs/gvfs-trash.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/programs/gvfs-trash.c b/programs/gvfs-trash.c
index 4654f21d..36dc02e0 100644
--- a/programs/gvfs-trash.c
+++ b/programs/gvfs-trash.c
@@ -27,11 +27,46 @@
#include <glib/gi18n.h>
#include <gio/gio.h>
+static void
+delete_trash_file (GFile *file, gboolean del_file, gboolean del_children)
+{
+ GFileInfo *info;
+ GFile *child;
+ GFileEnumerator *enumerator;
+
+ if (del_children)
+ {
+ enumerator = g_file_enumerate_children (file,
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL,
+ NULL);
+ if (enumerator)
+ {
+ 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);
+ g_object_unref (child);
+ g_object_unref (info);
+ }
+ g_file_enumerator_close (enumerator, NULL, NULL);
+ g_object_unref (enumerator);
+ }
+ }
+
+ if (del_file)
+ g_file_delete (file, NULL, NULL);
+}
+
static gboolean force = FALSE;
+static gboolean empty = FALSE;
static GOptionEntry entries[] =
{
- {"force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Ignore nonexistent files, never prompt"), NULL},
+ { "force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Ignore nonexistent files, never prompt"), NULL },
+ { "empty", 0, 0, G_OPTION_ARG_NONE, &empty, N_("Empty the trash"), NULL },
{ NULL }
};
@@ -93,5 +128,13 @@ main (int argc, char *argv[])
}
}
+ if (empty)
+ {
+ GFile *file;
+ file = g_file_new_for_uri ("trash:");
+ delete_trash_file (file, FALSE, TRUE);
+ g_object_unref (file);
+ }
+
return retval;
}