[glib/wip/oholy/fix-trash-symlink] glocalfile: Fix access::can-trash if parent is symlink



commit 7db70e79fd1d9851368be1976f280e723ba2478b
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Sep 13 17:33:59 2018 +0200

    glocalfile: Fix access::can-trash if parent is symlink
    
    G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH can be set to a wrong value if
    its parent dir is a symlink. This is because the find_mountpoint_for()
    function tries to find mountpoint for a filepath and expands symlinks
    only in parent dirs. But in this case the path is already parent dir
    and needs to be expanded first...
    
    Closes: https://gitlab.gnome.org/GNOME/glib/issues/1522

 gio/glocalfile.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index 30fa2281c..68e8959ff 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -1769,7 +1769,7 @@ _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
 {
   static gsize home_dev_set = 0;
   static dev_t home_dev;
-  char *topdir, *globaldir, *trashdir, *tmpname;
+  char *topdir, *globaldir, *trashdir, *tmpname, *target;
   uid_t uid;
   char uid_str[32];
   GStatBuf global_stat, trash_stat;
@@ -1789,7 +1789,14 @@ _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
   if (dir_dev == home_dev)
     return TRUE;
 
-  topdir = find_mountpoint_for (dirname, dir_dev);
+  /* find_mountpoint_for() expands symlinks, however, just for parents, but
+   * dirname is already parent and might be symlink, try to expand it...
+   */
+  target = expand_symlink (dirname);
+
+  topdir = find_mountpoint_for (target, dir_dev);
+  g_free (target);
+
   if (topdir == NULL)
     return FALSE;
 


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