[gvfs] Add -f support to gvfs-rm and gvfs-trash



commit f20369496be7bdb7a614916367c6d4fd459dd44a
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Aug 24 16:25:04 2009 +0200

    Add -f support to gvfs-rm and gvfs-trash
    
    Also clean up things a bit, and fix up translations.

 programs/gvfs-rm.c    |   25 ++++++++++++++++---------
 programs/gvfs-trash.c |   25 +++++++++++++++----------
 2 files changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/programs/gvfs-rm.c b/programs/gvfs-rm.c
index cb66654..85f4fa0 100644
--- a/programs/gvfs-rm.c
+++ b/programs/gvfs-rm.c
@@ -1,5 +1,5 @@
 /* GIO - GLib Input, Output and Streaming Library
- * 
+ *
  * Copyright (C) 2006-2007 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -24,11 +24,16 @@
 
 #include <glib.h>
 #include <locale.h>
+#include <glib/gi18n.h>
 #include <gio/gio.h>
 
-static GOptionEntry entries[] = 
+static gboolean force = FALSE;
+
+static GOptionEntry entries[] =
 {
-	{ NULL }
+  {"force", 'f', 0, G_OPTION_ARG_NONE, &force,
+   N_("ignore nonexistent files, never prompt"), NULL},
+  { NULL }
 };
 
 
@@ -38,27 +43,29 @@ main (int argc, char *argv[])
   GError *error;
   GOptionContext *context;
   GFile *file;
-  
+
   setlocale (LC_ALL, "");
 
   g_type_init ();
-  
+
   error = NULL;
-  context = g_option_context_new ("- delete files");
+  context = g_option_context_new (_("- delete files"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
   g_option_context_parse (context, &argc, &argv, &error);
   g_option_context_free (context);
-  
+
   if (argc > 1)
     {
       int i;
-      
+
       for (i = 1; i < argc; i++) {
 	file = g_file_new_for_commandline_arg (argv[i]);
 	error = NULL;
 	if (!g_file_delete (file, NULL, &error))
 	  {
-	    g_print ("Error deleting file: %s\n", error->message);
+	    if (!force ||
+		!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+	      g_printerr ("Error deleting file: %s\n", error->message);
 	    g_error_free (error);
 	  }
 	g_object_unref (file);
diff --git a/programs/gvfs-trash.c b/programs/gvfs-trash.c
index 7fa1aec..d8689a4 100644
--- a/programs/gvfs-trash.c
+++ b/programs/gvfs-trash.c
@@ -1,5 +1,5 @@
 /* GIO - GLib Input, Output and Streaming Library
- * 
+ *
  * Copyright (C) 2006-2007 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -24,42 +24,47 @@
 
 #include <glib.h>
 #include <locale.h>
+#include <glib/gi18n.h>
 #include <gio/gio.h>
 
+static gboolean force = FALSE;
 
-static GOptionEntry entries[] = 
+static GOptionEntry entries[] =
 {
-	{ NULL }
+  {"force", 'f', 0, G_OPTION_ARG_NONE, &force,
+   N_("ignore nonexistent files, never prompt"), NULL},
+  { NULL }
 };
 
-
 int
 main (int argc, char *argv[])
 {
   GError *error;
   GOptionContext *context;
   GFile *file;
-  
+
   setlocale (LC_ALL, "");
 
   g_type_init ();
-  
+
   error = NULL;
-  context = g_option_context_new ("- move files to trash");
+  context = g_option_context_new (_("- move files to trash"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
   g_option_context_parse (context, &argc, &argv, &error);
   g_option_context_free (context);
-  
+
   if (argc > 1)
     {
       int i;
-      
+
       for (i = 1; i < argc; i++) {
 	file = g_file_new_for_commandline_arg (argv[i]);
 	error = NULL;
 	if (!g_file_trash (file, NULL, &error))
 	  {
-	    g_print ("Error trashing file: %s\n", error->message);
+	    if (!force ||
+		!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+	      g_printerr (_("Error trashing file: %s\n"), error->message);
 	    g_error_free (error);
 	  }
 	g_object_unref (file);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]