[glib] gdesktopappinfo: Call g_file_get_path() on demand



commit 2d8e5ef81e8116eeb8fea18292360dd3166b4b4e
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Sep 25 16:14:17 2013 +0200

    gdesktopappinfo: Call g_file_get_path() on demand
    
    Rather than always calling out to g_file_get_path() (which
    might block, whatever the documentation might say), postpone
    the call until we actually need it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=708753

 gio/gdesktopappinfo.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index f7f0169..b584942 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -869,11 +869,10 @@ expand_macro_single (char macro, char *uri)
 {
   GFile *file;
   char *result = NULL;
-  char *path, *name;
+  char *path = NULL;
+  char *name;
 
   file = g_file_new_for_uri (uri);
-  path = g_file_get_path (file);
-  g_object_unref (file);
   
   switch (macro)
     {
@@ -883,11 +882,13 @@ expand_macro_single (char macro, char *uri)
       break;
     case 'f':
     case 'F':
+      path = g_file_get_path (file);
       if (path)
        result = g_shell_quote (path);
       break;
     case 'd':
     case 'D':
+      path = g_file_get_path (file);
       if (path)
         {
           name = g_path_get_dirname (path);
@@ -897,6 +898,7 @@ expand_macro_single (char macro, char *uri)
       break;
     case 'n':
     case 'N':
+      path = g_file_get_path (file);
       if (path)
         {
           name = g_path_get_basename (path);
@@ -906,6 +908,7 @@ expand_macro_single (char macro, char *uri)
       break;
     }
 
+  g_object_unref (file);
   g_free (path);
   
   return result;


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