[glib/sandboxed-dbus-activation] Fix a few errors



commit af288050fade894a344d5426c0b4aa1024d18a73
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 13 16:41:11 2017 -0400

    Fix a few errors
    
    These were found in testing.

 gio/gdesktopappinfo.c |   47 ++++++++++++++++++++++++++++-------------------
 1 files changed, 28 insertions(+), 19 deletions(-)
---
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index 0f0b256..469dd0c 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -2884,7 +2884,8 @@ static void
 free_launch_data (LaunchData *data)
 {
   g_object_unref (data->info);
-  g_object_unref (data->context);
+  if (data->context)
+    g_object_unref (data->context);
   g_list_free_full (data->uris, g_free);
   g_free (data->as_is);
   g_free (data);
@@ -2962,9 +2963,9 @@ rewrite_uris_for_portal (GDesktopAppInfo   *info,
 
   data = g_new (LaunchData, 1);
   data->info = g_object_ref (info);
-  data->context = g_object_ref (context);
+  data->context = context ? g_object_ref (context) : NULL;
   data->uris = g_list_copy_deep (uris, (GCopyFunc)g_strdup, NULL);
-  data->as_is = g_new (gboolean, g_list_length (uris));
+  data->as_is = g_new0 (gboolean, g_list_length (uris));
 
   g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
   g_variant_builder_add (&builder, "s", info->app_id);
@@ -2976,12 +2977,12 @@ rewrite_uris_for_portal (GDesktopAppInfo   *info,
       const char *uri = l->data;
       int idx = -1;
 
-      if (g_str_has_prefix (uri, "file:"))
+      if (g_str_has_prefix (uri, "file://"))
         {
           const char *path;
           int fd;
 
-          path = uri + strlen ("file:");
+          path = uri + strlen ("file://");
 
           fd = open (path, O_CLOEXEC | O_PATH);
           if (fd >= 0)
@@ -2991,26 +2992,34 @@ rewrite_uris_for_portal (GDesktopAppInfo   *info,
             }
         }
 
-      data->as_is[i] = idx != -1;
       if (idx != -1)
         g_variant_builder_add (&builder, "h", idx);
+      else
+        data->as_is[i] = TRUE;
     }
 
   g_variant_builder_close (&builder);
 
-  g_dbus_connection_call_with_unix_fd_list (session_bus,
-                                            "org.freedesktop.portal.Documents",
-                                            "/org/freedesktop/portal/documents",
-                                            "org.freedesktop.portal.Documents",
-                                            "AddMany",
-                                            g_variant_builder_end (&builder),
-                                            G_VARIANT_TYPE ("(asay)"),
-                                            G_DBUS_CALL_FLAGS_NONE,
-                                            -1,
-                                            fd_list,
-                                            NULL,
-                                            rewrite_uris_done,
-                                            data);
+  if (g_unix_fd_list_get_length (fd_list) > 0)
+    g_dbus_connection_call_with_unix_fd_list (session_bus,
+                                              "org.freedesktop.portal.Documents",
+                                              "/org/freedesktop/portal/documents",
+                                              "org.freedesktop.portal.Documents",
+                                              "AddMany",
+                                              g_variant_builder_end (&builder),
+                                              G_VARIANT_TYPE ("(asay)"),
+                                              G_DBUS_CALL_FLAGS_NONE,
+                                              -1,
+                                              fd_list,
+                                              NULL,
+                                              rewrite_uris_done,
+                                              data);
+  else
+    {
+      launch_uris_with_dbus (info, session_bus, uris, context);
+      free_launch_data (data);
+    }
+
   g_object_unref (fd_list);
 }
 


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