Coverage Report

Created: 2026-09-01 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/irssi/subprojects/glib-2.74.7/gio/gportalsupport.c
Line
Count
Source
1
/* GIO - GLib Input, Output and Streaming Library
2
 *
3
 * Copyright 2016 Red Hat, Inc.
4
 *
5
 * SPDX-License-Identifier: LGPL-2.1-or-later
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General
18
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "config.h"
22
23
#include "gportalsupport.h"
24
25
static gboolean use_portal;
26
static gboolean network_available;
27
static gboolean dconf_access;
28
29
static void
30
read_flatpak_info (void)
31
0
{
32
0
  static gsize flatpak_info_read = 0;
33
0
  const gchar *path = "/.flatpak-info";
34
35
0
  if (!g_once_init_enter (&flatpak_info_read))
36
0
    return;
37
38
0
  if (g_file_test (path, G_FILE_TEST_EXISTS))
39
0
    {
40
0
      GKeyFile *keyfile;
41
42
0
      use_portal = TRUE;
43
0
      network_available = FALSE;
44
0
      dconf_access = FALSE;
45
46
0
      keyfile = g_key_file_new ();
47
0
      if (g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL))
48
0
        {
49
0
          char **shared = NULL;
50
0
          char *dconf_policy = NULL;
51
52
0
          shared = g_key_file_get_string_list (keyfile, "Context", "shared", NULL, NULL);
53
0
          if (shared)
54
0
            {
55
0
              network_available = g_strv_contains ((const char * const *)shared, "network");
56
0
              g_strfreev (shared);
57
0
            }
58
59
0
          dconf_policy = g_key_file_get_string (keyfile, "Session Bus Policy", "ca.desrt.dconf", NULL);
60
0
          if (dconf_policy)
61
0
            {
62
0
              if (strcmp (dconf_policy, "talk") == 0)
63
0
                dconf_access = TRUE;
64
0
              g_free (dconf_policy);
65
0
            }
66
0
        }
67
68
0
      g_key_file_unref (keyfile);
69
0
    }
70
0
  else
71
0
    {
72
0
      const char *var;
73
74
0
      var = g_getenv ("GTK_USE_PORTAL");
75
0
      if (var && var[0] == '1')
76
0
        use_portal = TRUE;
77
0
      network_available = TRUE;
78
0
      dconf_access = TRUE;
79
0
    }
80
81
0
  g_once_init_leave (&flatpak_info_read, 1);
82
0
}
83
84
gboolean
85
glib_should_use_portal (void)
86
0
{
87
0
  read_flatpak_info ();
88
0
  return use_portal;
89
0
}
90
91
gboolean
92
glib_network_available_in_sandbox (void)
93
0
{
94
0
  read_flatpak_info ();
95
0
  return network_available;
96
0
}
97
98
gboolean
99
glib_has_dconf_access_in_sandbox (void)
100
0
{
101
0
  read_flatpak_info ();
102
0
  return dconf_access;
103
0
}