File: gutils-Move-the-special-case-default-value-for-G_USER_DIR.patch

package info (click to toggle)
glib2.0 2.86.0-6
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 74,852 kB
  • sloc: ansic: 544,570; python: 9,702; sh: 1,612; xml: 1,482; perl: 1,222; cpp: 535; makefile: 321; javascript: 11
file content (69 lines) | stat: -rw-r--r-- 2,534 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From: Philip Withnall <pwithnall@gnome.org>
Date: Fri, 19 Sep 2025 13:29:07 +0100
Subject: gutils: Move the special case default value for
 G_USER_DIRECTORY_DESKTOP
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

Otherwise it isn’t set on every code path, and it’s possible for a
caller to receive `NULL` when they call `g_get_user_special_dir
(G_USER_DIRECTORY_DESKTOP)`, i.e. after calling
`g_reload_user_special_dirs_cache()`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Origin: upstream, 2.86.1, commit:964c3f10699f000dba996ce13d04de7f28b63e41
---
 glib/gutils.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/glib/gutils.c b/glib/gutils.c
index 4d19ddb..02da41b 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -2279,21 +2279,20 @@ load_user_special_dirs_unlocked (void)
   const gchar *config_dir = NULL;
   const gchar *home_dir;
   gchar *config_file;
-  gchar *data;
+  char *data = NULL;
 
   config_dir = g_get_user_config_dir_unlocked ();
   config_file = g_build_filename (config_dir,
                                   "user-dirs.dirs",
                                   NULL);
+  home_dir = g_get_home_dir_unlocked ();
 
-  if (!g_file_get_contents (config_file, &data, NULL, NULL))
-    {
-      g_free (config_file);
-      return;
-    }
+  if (g_file_get_contents (config_file, &data, NULL, NULL))
+    load_user_special_dirs_from_string (data, home_dir, g_user_special_dirs);
 
-  home_dir = g_get_home_dir_unlocked ();
-  load_user_special_dirs_from_string (data, home_dir, g_user_special_dirs);
+  /* Special-case desktop for historical compatibility */
+  if (g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] == NULL)
+    g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] = g_build_filename (home_dir, "Desktop", NULL);
 
   g_free (data);
   g_free (config_file);
@@ -2392,16 +2391,7 @@ g_get_user_special_dir (GUserDirectory directory)
   if (G_UNLIKELY (g_user_special_dirs == NULL))
     {
       g_user_special_dirs = g_new0 (gchar *, G_USER_N_DIRECTORIES);
-
       load_user_special_dirs_unlocked ();
-
-      /* Special-case desktop for historical compatibility */
-      if (g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] == NULL)
-        {
-          gchar *home_dir = g_build_home_dir ();
-          g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] = g_build_filename (home_dir, "Desktop", NULL);
-          g_free (home_dir);
-        }
     }
   user_special_dir = g_user_special_dirs[directory];