[gvfs/wip/oholy/udisks2-media-user] udisks2: Include only direct subdirectories of /media




commit 7e4267796078e312b96a34881fdece8739c3939a
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Oct 30 08:48:11 2020 +0100

    udisks2: Include only direct subdirectories of /media
    
    Currently, all mounts with `/media` prefix are returned from the volume
    monitor (except those with `x-gvfs-hide`, or dot at the beginning). However,
    some distributions don't use `/run/media/$USER`, but `/media/$USER` as
    the default prefix. Consequently, the volume monitor also returns mounts
    that are not accessible as they belong to other users, which is wrong.
    It would be ideal to check the mounts using e.g. `access (mount_path, R_OK)`,
    but this would automount autofs mounts, or would possibly hang on stale NFS
    mounts. Let's skip mounts that are not direct subdirectories of `/mount`
    with an exception for `/media/$USER` and those with `x-gvfs-show` to fix
    this issue.
    
    https://discourse.gnome.org/t/4546

 monitor/udisks2/gvfsudisks2volumemonitor.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/monitor/udisks2/gvfsudisks2volumemonitor.c b/monitor/udisks2/gvfsudisks2volumemonitor.c
index 4ecabd99..02c04010 100644
--- a/monitor/udisks2/gvfsudisks2volumemonitor.c
+++ b/monitor/udisks2/gvfsudisks2volumemonitor.c
@@ -606,6 +606,8 @@ update_all (GVfsUDisks2VolumeMonitor *monitor,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+
+
 static gboolean
 should_include (const gchar *mount_path,
                 const gchar *options)
@@ -642,9 +644,9 @@ should_include (const gchar *mount_path,
     goto out;
 
   /* Only display things in
-   * - /media; and
+   * - direct subdirectories of /media; and
    * - $HOME; and
-   * - /run/media/$USER
+   * - /media/$USER and /run/media/$USER
    */
 
   /* Hide mounts within a subdirectory starting with a "." - suppose it was a purpose to hide this mount */
@@ -652,7 +654,8 @@ should_include (const gchar *mount_path,
     goto out;
 
   /* Check /media */
-  if (g_str_has_prefix (mount_path, "/media/"))
+  if (g_str_has_prefix (mount_path, "/media/") &&
+      g_strrstr (mount_path, "/") == mount_path + strlen ("/media/") - 1)
     {
       ret = TRUE;
       goto out;
@@ -669,9 +672,17 @@ should_include (const gchar *mount_path,
         }
     }
 
-  /* Check /run/media/$USER/ */
+  /* Check /media/$USER/ and /run/media/$USER/ */
   user_name = g_get_user_name ();
   user_name_len = strlen (user_name);
+  if (strncmp (mount_path, "/media/", sizeof ("/media/") - 1) == 0 &&
+      strncmp (mount_path + sizeof ("/media/") - 1, user_name, user_name_len) == 0 &&
+      mount_path[sizeof ("/media/") - 1 + user_name_len] == '/')
+    {
+      ret = TRUE;
+      goto out;
+    }
+
   if (strncmp (mount_path, "/run/media/", sizeof ("/run/media/") - 1) == 0 &&
       strncmp (mount_path + sizeof ("/run/media/") - 1, user_name, user_name_len) == 0 &&
       mount_path[sizeof ("/run/media/") - 1 + user_name_len] == '/')


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