[glib] gio: Error out when we cannot modify a GAppInfo



commit 229234111c418c2186868c47bfdd6684be8ee1cf
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Aug 26 16:36:12 2011 +0100

    gio: Error out when we cannot modify a GAppInfo
    
    g_desktop_app_info_set_as_default_for_type() and
    g_desktop_app_info_set_as_last_used_for_type () require the
    application's ID, but depending on how the GAppInfo was created,
    we might not be have one, and would thus silently fail to set
    the default application, or last used application.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=657445

 gio/gdesktopappinfo.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index 6bd6a0d..64f0349 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -1779,6 +1779,13 @@ g_desktop_app_info_set_as_last_used_for_type (GAppInfo    *appinfo,
   if (!g_desktop_app_info_ensure_saved (info, error))
     return FALSE;
 
+  if (!info->desktop_id)
+    {
+      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                           _("Application information lacks an identifier"));
+      return FALSE;
+    }
+
   /* both add support for the content type and set as last used */
   return update_mimeapps_list (info->desktop_id, content_type,
                                UPDATE_MIME_SET_NON_DEFAULT |
@@ -1794,8 +1801,15 @@ g_desktop_app_info_set_as_default_for_type (GAppInfo    *appinfo,
   GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
 
   if (!g_desktop_app_info_ensure_saved (info, error))
-    return FALSE;  
-  
+    return FALSE;
+
+  if (!info->desktop_id)
+    {
+      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                           _("Application information lacks an identifier"));
+      return FALSE;
+    }
+
   return update_mimeapps_list (info->desktop_id, content_type,
                                UPDATE_MIME_SET_DEFAULT,
                                error);



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