[glib/wip/oholy/x-gvfs-notrash: 9/10] gunixmounts: Add g_unix_mount_point_at




commit 3db70240de75dcecfe9efaa8ec71c50f36a6f72c
Author: Ondrej Holy <oholy redhat com>
Date:   Tue Jun 23 08:23:16 2020 +0200

    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.

 docs/reference/gio/gio-sections-common.txt |  1 +
 gio/gunixmounts.c                          | 46 ++++++++++++++++++++++++++++++
 gio/gunixmounts.h                          |  3 ++
 3 files changed, 50 insertions(+)
---
diff --git a/docs/reference/gio/gio-sections-common.txt b/docs/reference/gio/gio-sections-common.txt
index 9e606a1f0..19e067f98 100644
--- a/docs/reference/gio/gio-sections-common.txt
+++ b/docs/reference/gio/gio-sections-common.txt
@@ -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
diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c
index 0d3fa68b0..b0fdfa8c0 100644
--- a/gio/gunixmounts.c
+++ b/gio/gunixmounts.c
@@ -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.
diff --git a/gio/gunixmounts.h b/gio/gunixmounts.h
index fe8e24160..2553e1ca1 100644
--- a/gio/gunixmounts.h
+++ b/gio/gunixmounts.h
@@ -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


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