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
This commit is contained in:
Ondrej Holy 2019-03-22 10:51:24 +01:00
parent 1a03ebc43a
commit bc52235efc

View File

@ -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