[gvfs] gvfs-open: Exit with error code > 0 when open fails



commit b76c3e8053a44b971c5fc8b6ff9d5adfb6557eb5
Author: Rodrigo Silva <gnome rodrigosilva com>
Date:   Tue Aug 23 16:47:09 2011 +0200

    gvfs-open: Exit	with error code > 0 when open fails
    
    Previously gvfs-open exited with success (error code 0) even when open
    failed, either because file was not found or there was no default
    application registred to open it. Without easy testing for error codes,
    it was hard to use it in scripts. Now it exits with code 1 when any of
    the given files are either not found or its default application is not
    registered.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=655470

 programs/gvfs-open.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/programs/gvfs-open.c b/programs/gvfs-open.c
index 7e197d8..c72a896 100644
--- a/programs/gvfs-open.c
+++ b/programs/gvfs-open.c
@@ -47,7 +47,7 @@ is_file_uri_with_anchor (char *str)
   return FALSE;
 }
 
-static void
+static gboolean
 open (GFile *file, char *arg_string)
 {
   GAppInfo *app;
@@ -65,7 +65,7 @@ open (GFile *file, char *arg_string)
       g_printerr (_("%s: %s: error opening location: %s\n"),
 		  g_get_prgname (), g_file_get_uri (file), error->message);
       g_error_free (error);
-      return;
+      return FALSE;
     }
 
   if (g_file_is_native (file) && !is_file_uri_with_anchor (arg_string))
@@ -96,7 +96,7 @@ open (GFile *file, char *arg_string)
 
   g_object_unref (app);
 
-  return;
+  return res;
 }
 
 int
@@ -107,6 +107,7 @@ main (int argc, char *argv[])
   GFile *file;
   gchar *summary;
   int i;
+  gint res;
 
   setlocale (LC_ALL, "");
 
@@ -157,14 +158,17 @@ main (int argc, char *argv[])
     }
 
   i = 0;
+  res = 0;
 
   do
     {
       file = g_file_new_for_commandline_arg (locations[i]);
-      open (file, locations[i]);
+      res += !open (file, locations[i]);
       g_object_unref (file);
     }
   while (locations[++i] != NULL);
+  if (res)
+    return 2;
 
   return 0;
 }



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