[gvfs/wip/oholy/x-gvfs-ignore: 1/3] common: Move some mount helpers to common



commit 787b86ec1f1ec5c299e7f2e2b4a245c887ceaa7f
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Feb 28 11:20:11 2019 +0100

    common: Move some mount helpers to common
    
    Move gvfs_udisks2_utils_lookup_fstab_options_value() and
    get_mount_point_for_mount() to common library, so we can use them
    on other places as well.
    
    https://gitlab.gnome.org/GNOME/gvfs/issues/375

 common/gvfsutils.c                         | 61 ++++++++++++++++++++++++++++++
 common/gvfsutils.h                         |  6 +++
 common/meson.build                         |  2 +-
 monitor/udisks2/gvfsudisks2utils.c         | 32 ----------------
 monitor/udisks2/gvfsudisks2utils.h         |  3 --
 monitor/udisks2/gvfsudisks2volume.c        |  7 ++--
 monitor/udisks2/gvfsudisks2volumemonitor.c | 38 ++-----------------
 7 files changed, 76 insertions(+), 73 deletions(-)
---
diff --git a/common/gvfsutils.c b/common/gvfsutils.c
index cb994e4f..0f1f6ce7 100644
--- a/common/gvfsutils.c
+++ b/common/gvfsutils.c
@@ -145,3 +145,64 @@ gvfs_is_ipv6 (const char *host)
 
   return TRUE;
 }
+
+gchar *
+gvfs_lookup_fstab_options_value (const gchar *fstab_options,
+                                 const gchar *key)
+{
+  gchar *ret = NULL;
+
+  if (fstab_options != NULL)
+    {
+      const gchar *start;
+      guint n;
+
+      /* The code doesn't care about prefix, which may cause problems for
+       * options like "auto" and "noauto". However, this function is only used
+       * with our "x-gvfs-*" options, where mentioned problems are unlikely.
+       * Be careful, that some people rely on this bug and use "comment=x-gvfs-*"
+       * as workaround, see: https://gitlab.gnome.org/GNOME/gvfs/issues/348
+       */
+      start = strstr (fstab_options, key);
+      if (start != NULL)
+        {
+          start += strlen (key);
+          for (n = 0; start[n] != ',' && start[n] != '\0'; n++)
+            ;
+          if (n == 0)
+            ret = g_strdup ("");
+          else if (n >= 1)
+            ret = g_uri_unescape_segment (start, start + n, NULL);
+        }
+    }
+  return ret;
+}
+
+GUnixMountPoint *
+gvfs_get_mount_point_for_mount (GUnixMountEntry *mount_entry)
+{
+  GUnixMountPoint *ret = NULL;
+  GList *mount_points, *l;
+
+  mount_points = g_unix_mount_points_get (NULL);
+  for (l = mount_points; l != NULL; l = l->next)
+    {
+      GUnixMountPoint *mount_point = l->data;
+      if (g_strcmp0 (g_unix_mount_get_mount_path (mount_entry),
+                     g_unix_mount_point_get_mount_path (mount_point)) == 0)
+        {
+          ret = mount_point;
+          goto out;
+        }
+    }
+
+ out:
+  for (l = mount_points; l != NULL; l = l->next)
+    {
+      GUnixMountPoint *mount_point = l->data;
+      if (G_LIKELY (mount_point != ret))
+        g_unix_mount_point_free (mount_point);
+    }
+  g_list_free (mount_points);
+  return ret;
+}
diff --git a/common/gvfsutils.h b/common/gvfsutils.h
index acaea9d2..d6f6e81b 100644
--- a/common/gvfsutils.h
+++ b/common/gvfsutils.h
@@ -20,6 +20,8 @@
 #ifndef __G_VFS_UTILS_H__
 #define __G_VFS_UTILS_H__
 
+#include <gio/gunixmounts.h>
+
 G_BEGIN_DECLS
 
 void         gvfs_randomize_string                  (char             *str,
@@ -32,6 +34,10 @@ void         gvfs_setup_debug_handler               (void);
 
 gboolean     gvfs_is_ipv6                           (const char       *host);
 
+gchar       *gvfs_lookup_fstab_options_value        (const gchar      *fstab_options,
+                                                     const gchar      *key);
+GUnixMountPoint *gvfs_get_mount_point_for_mount     (GUnixMountEntry  *mount_entry);
+
 G_END_DECLS
 
 #endif /* __G_VFS_UTILS_H__ */
diff --git a/common/meson.build b/common/meson.build
index b2a2f250..3c783957 100644
--- a/common/meson.build
+++ b/common/meson.build
@@ -43,7 +43,7 @@ libgvfscommon = shared_library(
 libgvfscommon_dep = declare_dependency(
   sources: dbus_sources[1],
   include_directories: common_inc,
-  dependencies: deps,
+  dependencies: deps + [gio_unix_dep],
   link_with: libgvfscommon,
 )
 
diff --git a/monitor/udisks2/gvfsudisks2utils.c b/monitor/udisks2/gvfsudisks2utils.c
index df56962b..5ceb2b47 100644
--- a/monitor/udisks2/gvfsudisks2utils.c
+++ b/monitor/udisks2/gvfsudisks2utils.c
@@ -99,38 +99,6 @@ gvfs_udisks2_utils_symbolic_icon_from_fs_type (const gchar *fs_type)
   return g_themed_icon_new_with_default_fallbacks (icon_name);
 }
 
-gchar *
-gvfs_udisks2_utils_lookup_fstab_options_value (const gchar *fstab_options,
-                                               const gchar *key)
-{
-  gchar *ret = NULL;
-
-  if (fstab_options != NULL)
-    {
-      const gchar *start;
-      guint n;
-
-      /* The code doesn't care about prefix, which may cause problems for
-       * options like "auto" and "noauto". However, this function is only used
-       * with our "x-gvfs-*" options, where mentioned problems are unlikely.
-       * Be careful, that some people rely on this bug and use "comment=x-gvfs-*"
-       * as workaround, see: https://gitlab.gnome.org/GNOME/gvfs/issues/348
-       */
-      start = strstr (fstab_options, key);
-      if (start != NULL)
-        {
-          start += strlen (key);
-          for (n = 0; start[n] != ',' && start[n] != '\0'; n++)
-            ;
-          if (n == 0)
-            ret = g_strdup ("");
-          else if (n >= 1)
-            ret = g_uri_unescape_segment (start, start + n, NULL);
-        }
-    }
-  return ret;
-}
-
 /* ---------------------------------------------------------------------------------------------------- */
 
 typedef struct
diff --git a/monitor/udisks2/gvfsudisks2utils.h b/monitor/udisks2/gvfsudisks2utils.h
index fbd699b5..ca0b34f5 100644
--- a/monitor/udisks2/gvfsudisks2utils.h
+++ b/monitor/udisks2/gvfsudisks2utils.h
@@ -35,9 +35,6 @@ void   gvfs_udisks2_utils_udisks_error_to_gio_error (GError *error);
 GIcon *gvfs_udisks2_utils_icon_from_fs_type (const gchar *fs_type);
 GIcon *gvfs_udisks2_utils_symbolic_icon_from_fs_type (const gchar *fs_type);
 
-gchar *gvfs_udisks2_utils_lookup_fstab_options_value (const gchar *fstab_options,
-                                                      const gchar *key);
-
 void     gvfs_udisks2_utils_spawn (guint                timeout_seconds,
                                    GCancellable        *cancellable,
                                    GAsyncReadyCallback  callback,
diff --git a/monitor/udisks2/gvfsudisks2volume.c b/monitor/udisks2/gvfsudisks2volume.c
index a509b5dd..07a0e1ea 100644
--- a/monitor/udisks2/gvfsudisks2volume.c
+++ b/monitor/udisks2/gvfsudisks2volume.c
@@ -40,6 +40,7 @@
 #include "gvfsudisks2volume.h"
 #include "gvfsudisks2mount.h"
 #include "gvfsudisks2utils.h"
+#include "gvfsutils.h"
 
 typedef struct _GVfsUDisks2VolumeClass GVfsUDisks2VolumeClass;
 
@@ -187,14 +188,14 @@ apply_options_from_fstab (GVfsUDisks2Volume *volume,
   gchar *icon_name;
   gchar *symbolic_icon_name;
 
-  name = gvfs_udisks2_utils_lookup_fstab_options_value (fstab_options, "x-gvfs-name=");
+  name = gvfs_lookup_fstab_options_value (fstab_options, "x-gvfs-name=");
   if (name != NULL)
     {
       g_free (volume->name);
       volume->name = name;
     }
 
-  icon_name = gvfs_udisks2_utils_lookup_fstab_options_value (fstab_options, "x-gvfs-icon=");
+  icon_name = gvfs_lookup_fstab_options_value (fstab_options, "x-gvfs-icon=");
   if (icon_name != NULL)
     {
       g_clear_object (&volume->icon);
@@ -202,7 +203,7 @@ apply_options_from_fstab (GVfsUDisks2Volume *volume,
       g_free (icon_name);
     }
 
-  symbolic_icon_name = gvfs_udisks2_utils_lookup_fstab_options_value (fstab_options, 
"x-gvfs-symbolic-icon=");
+  symbolic_icon_name = gvfs_lookup_fstab_options_value (fstab_options, "x-gvfs-symbolic-icon=");
   if (symbolic_icon_name != NULL)
     {
       g_clear_object (&volume->symbolic_icon);
diff --git a/monitor/udisks2/gvfsudisks2volumemonitor.c b/monitor/udisks2/gvfsudisks2volumemonitor.c
index 0a5ce96e..ff522912 100644
--- a/monitor/udisks2/gvfsudisks2volumemonitor.c
+++ b/monitor/udisks2/gvfsudisks2volumemonitor.c
@@ -40,6 +40,7 @@
 #include "gvfsudisks2volume.h"
 #include "gvfsudisks2mount.h"
 #include "gvfsudisks2utils.h"
+#include "gvfsutils.h"
 
 static GVfsUDisks2VolumeMonitor *the_volume_monitor = NULL;
 
@@ -572,37 +573,6 @@ update_all (GVfsUDisks2VolumeMonitor *monitor,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static GUnixMountPoint *
-get_mount_point_for_mount (GUnixMountEntry *mount_entry)
-{
-  GUnixMountPoint *ret = NULL;
-  GList *mount_points, *l;
-
-  mount_points = g_unix_mount_points_get (NULL);
-  for (l = mount_points; l != NULL; l = l->next)
-    {
-      GUnixMountPoint *mount_point = l->data;
-      if (g_strcmp0 (g_unix_mount_get_mount_path (mount_entry),
-                     g_unix_mount_point_get_mount_path (mount_point)) == 0)
-        {
-          ret = mount_point;
-          goto out;
-        }
-    }
-
- out:
-  for (l = mount_points; l != NULL; l = l->next)
-    {
-      GUnixMountPoint *mount_point = l->data;
-      if (G_LIKELY (mount_point != ret))
-        g_unix_mount_point_free (mount_point);
-    }
-  g_list_free (mount_points);
-  return ret;
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
 static gboolean
 should_include (const gchar *mount_path,
                 const gchar *options)
@@ -618,14 +588,14 @@ should_include (const gchar *mount_path,
   if (options != NULL)
     {
       gchar *value;
-      value = gvfs_udisks2_utils_lookup_fstab_options_value (options, "x-gvfs-show");
+      value = gvfs_lookup_fstab_options_value (options, "x-gvfs-show");
       if (value != NULL)
         {
           ret = TRUE;
           g_free (value);
           goto out;
         }
-      value = gvfs_udisks2_utils_lookup_fstab_options_value (options, "x-gvfs-hide");
+      value = gvfs_lookup_fstab_options_value (options, "x-gvfs-hide");
       if (value != NULL)
         {
           ret = FALSE;
@@ -705,7 +675,7 @@ should_include_mount (GVfsUDisks2VolumeMonitor  *monitor,
    * in prior to g_unix_mount_get_options to keep support of "comment=" options,
    * see https://gitlab.gnome.org/GNOME/gvfs/issues/348.
    */
-  mount_point = get_mount_point_for_mount (mount_entry);
+  mount_point = gvfs_get_mount_point_for_mount (mount_entry);
   if (mount_point != NULL)
     {
       ret = should_include_mount_point (monitor, mount_point);


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