gunixmounts: Add g_unix_mount_point_at

There is already g_unix_mount_at function which allows to find certain
unix mount for given mount path. It would be useful to have similar
function for mount points, which will allow to replace custom codes in
gvfs. Let's add g_unix_mount_point_at.
This commit is contained in:
Ondrej Holy 2020-06-23 08:23:16 +02:00 committed by Philip Withnall
parent 50343afb6e
commit 0d6b17584a
3 changed files with 50 additions and 0 deletions

View File

@ -1572,6 +1572,7 @@ g_unix_mount_point_guess_symbolic_icon
g_unix_mount_point_guess_name
g_unix_mount_point_guess_can_eject
g_unix_mount_points_get
g_unix_mount_point_at
g_unix_mounts_get
g_unix_mount_at
g_unix_mount_for

View File

@ -1660,6 +1660,52 @@ g_unix_mount_points_get (guint64 *time_read)
return _g_get_unix_mount_points ();
}
/**
* g_unix_mount_point_at:
* @mount_path: (type filename): path for a possible unix mount point.
* @time_read: (out) (optional): guint64 to contain a timestamp.
*
* Gets a #GUnixMountPoint for a given mount path. If @time_read is set, it
* will be filled with a unix timestamp for checking if the mount points have
* changed since with g_unix_mount_points_changed_since().
*
* If more mount points have the same mount path, the last matching mount point
* is returned.
*
* Returns: (transfer full) (nullable): a #GUnixMountPoint, or %NULL if no match
* is found.
*
* Since: 2.66
**/
GUnixMountPoint *
g_unix_mount_point_at (const char *mount_path,
guint64 *time_read)
{
GList *mount_points, *l;
GUnixMountPoint *mount_point, *found;
mount_points = g_unix_mount_points_get (time_read);
found = NULL;
for (l = mount_points; l != NULL; l = l->next)
{
mount_point = l->data;
if (strcmp (mount_path, mount_point->mount_path) == 0)
{
if (found != NULL)
g_unix_mount_point_free (found);
found = mount_point;
}
else
g_unix_mount_point_free (mount_point);
}
g_list_free (mount_points);
return found;
}
/**
* g_unix_mounts_changed_since:
* @time: guint64 to contain a timestamp.

View File

@ -132,6 +132,9 @@ GIcon * g_unix_mount_point_guess_symbolic_icon (GUnixMountPoint *mount
GLIB_AVAILABLE_IN_ALL
GList * g_unix_mount_points_get (guint64 *time_read);
GLIB_AVAILABLE_IN_2_66
GUnixMountPoint *g_unix_mount_point_at (const char *mount_path,
guint64 *time_read);
GLIB_AVAILABLE_IN_ALL
GList * g_unix_mounts_get (guint64 *time_read);
GLIB_AVAILABLE_IN_ALL