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
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 @@
   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 @@
   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);