$OpenBSD: patch-gtk_gtkplacessidebar_c,v 1.9 2021/05/04 08:40:17 ajacoutot Exp $

unveil(2): check if the XDG directories exist before showing them on the sidebar

Index: gtk/gtkplacessidebar.c
--- gtk/gtkplacessidebar.c.orig
+++ gtk/gtkplacessidebar.c
@@ -600,6 +600,7 @@ add_special_dirs (GtkPlacesSidebar *sidebar)
        */
       if (path == NULL ||
           path_is_home_dir (path) ||
+	  !g_file_test (path, G_FILE_TEST_IS_DIR) ||
           g_list_find_custom (dirs, path, (GCompareFunc) g_strcmp0) != NULL)
         continue;
 
@@ -652,7 +653,8 @@ get_desktop_directory_uri (void)
   /* "To disable a directory, point it to the homedir."
    * See http://freedesktop.org/wiki/Software/xdg-user-dirs
    */
-  if (path_is_home_dir (name))
+  if ((name == NULL) || path_is_home_dir (name) ||
+       !g_file_test (name, G_FILE_TEST_IS_DIR))
     return NULL;
 
   return g_filename_to_uri (name, NULL, NULL);
@@ -1020,6 +1022,11 @@ update_places (GtkPlacesSidebar *sidebar)
 
   /* home folder */
   home_uri = get_home_directory_uri ();
+#if defined(__OpenBSD__)
+  if (!g_file_test (home_uri, G_FILE_TEST_IS_DIR))
+    goto skip_home;
+#endif
+
   start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_HOME);
   add_place (sidebar, GTK_PLACES_BUILT_IN,
              GTK_PLACES_SECTION_COMPUTER,
@@ -1029,6 +1036,9 @@ update_places (GtkPlacesSidebar *sidebar)
   g_object_unref (start_icon);
   g_free (home_uri);
 
+#if defined(__OpenBSD__)
+skip_home:
+#endif
   /* desktop */
   if (sidebar->show_desktop)
     {
