[glib/wip/oholy/trash-autofs] gunixmounts: Return the last matching mount for same mount path



commit bc52235efc265af6aa3e516ea2411e9a1f9ddbf1
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Mar 22 10:51:24 2019 +0100

    gunixmounts: Return the last matching mount for same mount path
    
    More mounts can have same mount path, but only the last one is
    accessible. Thus we should always return the last matching mount from
    g_unix_mount_at() and g_unix_mount_for(). This should also solve
    problems with g_file_trash() on automounted filesystems, which are
    caused by the recently added mount checks.
    
    Closes: https://gitlab.gnome.org/GNOME/glib/issues/1727

 gio/gunixmounts.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c
index cc905f2fc..44a4b113d 100644
--- a/gio/gunixmounts.c
+++ b/gio/gunixmounts.c
@@ -1552,6 +1552,9 @@ g_unix_mounts_get (guint64 *time_read)
  * is set, it will be filled with a unix timestamp for checking
  * if the mounts have changed since with g_unix_mounts_changed_since().
  * 
+ * If more mounts have the same mount path, the last matching mount
+ * is returned.
+ *
  * Returns: (transfer full): a #GUnixMountEntry.
  **/
 GUnixMountEntry *
@@ -1568,8 +1571,13 @@ g_unix_mount_at (const char *mount_path,
     {
       mount_entry = l->data;
 
-      if (!found && strcmp (mount_path, mount_entry->mount_path) == 0)
-        found = mount_entry;
+      if (strcmp (mount_path, mount_entry->mount_path) == 0)
+        {
+          if (found != NULL)
+            g_unix_mount_free (found);
+
+          found = mount_entry;
+        }
       else
         g_unix_mount_free (mount_entry);
     }
@@ -1587,6 +1595,9 @@ g_unix_mount_at (const char *mount_path,
  * is set, it will be filled with a unix timestamp for checking
  * if the mounts have changed since with g_unix_mounts_changed_since().
  *
+ * If more mounts have the same mount path, the last matching mount
+ * is returned.
+ *
  * Returns: (transfer full): a #GUnixMountEntry.
  *
  * Since: 2.52


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