[glib/wip/oholy/gio-mount-uuid] gio-tool-mount: Allow mounting by the given UUID



commit e976a12cd34c3aebfd23c779ab64c9f5e54d0ca1
Author: Ondrej Holy <oholy redhat com>
Date:   Tue Nov 26 09:15:45 2019 +0100

    gio-tool-mount: Allow mounting by the given UUID
    
    "gio mount" only allows mounting volumes using device files, but not using
    UUIDs. Volume monitors for various GVfs locations usually supports just UUIDs.
    It would be handy to support them also for testing purposes (because
    "g_file_mount_enclosing_volume()" does something else than "g_volume_mount()"
    in case of shares provided by GOA volume monitor for example). Let's update
    "-d" option to support also UUIDs.
    
    https://gitlab.gnome.org/GNOME/gvfs/issues/251

 gio/gio-tool-mount.c | 49 ++++++++++++++++++-------------------------------
 1 file changed, 18 insertions(+), 31 deletions(-)
---
diff --git a/gio/gio-tool-mount.c b/gio/gio-tool-mount.c
index 05647d91e..67278bb5c 100644
--- a/gio/gio-tool-mount.c
+++ b/gio/gio-tool-mount.c
@@ -53,7 +53,7 @@ static gboolean tcrypt_hidden = FALSE;
 static gboolean tcrypt_system = FALSE;
 static guint tcrypt_pim = 0;
 static const char *unmount_scheme = NULL;
-static const char *mount_device_file = NULL;
+static const char *mount_id = NULL;
 static const char *stop_device_file = NULL;
 static gboolean success = TRUE;
 
@@ -61,7 +61,7 @@ static gboolean success = TRUE;
 static const GOptionEntry entries[] =
 {
   { "mountable", 'm', 0, G_OPTION_ARG_NONE, &mount_mountable, N_("Mount as mountable"), NULL },
-  { "device", 'd', 0, G_OPTION_ARG_STRING, &mount_device_file, N_("Mount volume with device file"), 
N_("DEVICE") },
+  { "device", 'd', 0, G_OPTION_ARG_STRING, &mount_id, N_("Mount volume with device file, or other 
identifier"), N_("ID") },
   { "unmount", 'u', 0, G_OPTION_ARG_NONE, &mount_unmount, N_("Unmount"), NULL},
   { "eject", 'e', 0, G_OPTION_ARG_NONE, &mount_eject, N_("Eject"), NULL},
   { "stop", 't', 0, G_OPTION_ARG_STRING, &stop_device_file, N_("Stop drive with device file"), N_("DEVICE") 
},
@@ -950,7 +950,7 @@ mount_with_device_file_cb (GObject *object,
   GVolume *volume;
   gboolean succeeded;
   GError *error = NULL;
-  gchar *device_path = (gchar *)user_data;
+  gchar *id = (gchar *)user_data;
 
   volume = G_VOLUME (object);
 
@@ -958,28 +958,12 @@ mount_with_device_file_cb (GObject *object,
 
   if (!succeeded)
     {
-      print_error ("%s: %s", device_path, error->message);
+      print_error ("%s: %s", id, error->message);
       g_error_free (error);
       success = FALSE;
     }
-  else
-    {
-      GMount *mount;
-      GFile *root;
-      char *mount_path;
-
-      mount = g_volume_get_mount (volume);
-      root = g_mount_get_root (mount);
-      mount_path = g_file_get_path (root);
-
-      g_print (_("Mounted %s at %s\n"), device_path, mount_path);
-
-      g_object_unref (mount);
-      g_object_unref (root);
-      g_free (mount_path);
-    }
 
-  g_free (device_path);
+  g_free (id);
 
   outstanding_mounts--;
 
@@ -988,7 +972,7 @@ mount_with_device_file_cb (GObject *object,
 }
 
 static void
-mount_with_device_file (const char *device_file)
+mount_with_id (const char *id)
 {
   GList *volumes;
   GList *l;
@@ -997,10 +981,12 @@ mount_with_device_file (const char *device_file)
   for (l = volumes; l != NULL; l = l->next)
     {
       GVolume *volume = G_VOLUME (l->data);
-      gchar *id;
+      gchar *device;
+      gchar *uuid;
 
-      id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
-      if (g_strcmp0 (id, device_file) == 0)
+      device = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
+      uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID);
+      if (g_strcmp0 (device, id) == 0 || g_strcmp0 (uuid, id) == 0)
         {
           GMountOperation *op;
 
@@ -1011,20 +997,21 @@ mount_with_device_file (const char *device_file)
                           op,
                           NULL,
                           mount_with_device_file_cb,
-                          id);
+                          g_strdup (id));
 
           g_object_unref (op);
 
           outstanding_mounts++;
         }
-      else
-        g_free (id);
+
+      g_free (device);
+      g_free (uuid);
     }
   g_list_free_full (volumes, g_object_unref);
 
   if (outstanding_mounts == 0)
     {
-      print_error ("%s: %s", device_file, _("No volume for device file"));
+      print_error ("%s: %s", id, _("No volume for given ID"));
       success = FALSE;
     }
 }
@@ -1236,8 +1223,8 @@ handle_mount (int argc, char *argv[], gboolean do_help)
 
   if (mount_list)
     list_monitor_items ();
-  else if (mount_device_file != NULL)
-    mount_with_device_file (mount_device_file);
+  else if (mount_id != NULL)
+    mount_with_id (mount_id);
   else if (stop_device_file)
     stop_with_device_file (stop_device_file);
   else if (unmount_scheme != NULL)


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