[gtk+] placessidebar: use proper canonicalization when checking if home



commit 6ecc431c23ff284637c13bb6eccc39e114999fc6
Author: Cosimo Cecchi <cosimo endlessm com>
Date:   Wed May 14 11:19:56 2014 -0700

    placessidebar: use proper canonicalization when checking if home
    
    Instead of just checking the string. This catches things like double
    slashes, relative paths and so on.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=730142

 gtk/gtkplacessidebar.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index da0f019..2b6da81 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -582,6 +582,28 @@ should_show_recent (GtkPlacesSidebar *sidebar)
   return recent_files_setting_is_enabled (sidebar) && recent_scheme_is_supported ();
 }
 
+static gboolean
+path_is_home_dir (const gchar *path)
+{
+  GFile *home_dir;
+  GFile *location;
+  const gchar *home_path;
+  gboolean res;
+
+  home_path = g_get_home_dir ();
+  if (!home_path)
+    return FALSE;
+
+  home_dir = g_file_new_for_path (home_path);
+  location = g_file_new_for_path (path);
+  res = g_file_equal (home_dir, location);
+
+  g_object_unref (home_dir);
+  g_object_unref (location);
+
+  return res;
+}
+
 static void
 add_special_dirs (GtkPlacesSidebar *sidebar)
 {
@@ -608,7 +630,7 @@ add_special_dirs (GtkPlacesSidebar *sidebar)
        * to be added multiple times in that weird configuration.
        */
       if (path == NULL ||
-          g_strcmp0 (path, g_get_home_dir ()) == 0 ||
+          path_is_home_dir (path) ||
           g_list_find_custom (dirs, path, (GCompareFunc) g_strcmp0) != NULL)
         continue;
           
@@ -662,7 +684,7 @@ get_desktop_directory_uri (void)
   /* "To disable a directory, point it to the homedir."
    * See http://freedesktop.org/wiki/Software/xdg-user-dirs
    */
-  if (g_strcmp0 (name, g_get_home_dir ()) == 0)
+  if (path_is_home_dir (name))
     return NULL;
 
   return g_strconcat ("file://", name, NULL);


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