mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-28 06:56:16 +01:00
Merge branch 'wip/oholy/gio-mount-uuid' into 'master'
gio-tool-mount: Allow mounting by the given UUID See merge request GNOME/glib!1249
This commit is contained in:
commit
a937e99ca5
@ -53,7 +53,7 @@ static gboolean tcrypt_hidden = FALSE;
|
|||||||
static gboolean tcrypt_system = FALSE;
|
static gboolean tcrypt_system = FALSE;
|
||||||
static guint tcrypt_pim = 0;
|
static guint tcrypt_pim = 0;
|
||||||
static const char *unmount_scheme = NULL;
|
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 const char *stop_device_file = NULL;
|
||||||
static gboolean success = TRUE;
|
static gboolean success = TRUE;
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ static gboolean success = TRUE;
|
|||||||
static const GOptionEntry entries[] =
|
static const GOptionEntry entries[] =
|
||||||
{
|
{
|
||||||
{ "mountable", 'm', 0, G_OPTION_ARG_NONE, &mount_mountable, N_("Mount as mountable"), NULL },
|
{ "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},
|
{ "unmount", 'u', 0, G_OPTION_ARG_NONE, &mount_unmount, N_("Unmount"), NULL},
|
||||||
{ "eject", 'e', 0, G_OPTION_ARG_NONE, &mount_eject, N_("Eject"), 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") },
|
{ "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;
|
GVolume *volume;
|
||||||
gboolean succeeded;
|
gboolean succeeded;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gchar *device_path = (gchar *)user_data;
|
gchar *id = (gchar *)user_data;
|
||||||
|
|
||||||
volume = G_VOLUME (object);
|
volume = G_VOLUME (object);
|
||||||
|
|
||||||
@ -958,28 +958,12 @@ mount_with_device_file_cb (GObject *object,
|
|||||||
|
|
||||||
if (!succeeded)
|
if (!succeeded)
|
||||||
{
|
{
|
||||||
print_error ("%s: %s", device_path, error->message);
|
print_error ("%s: %s", id, error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
success = FALSE;
|
success = FALSE;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
GMount *mount;
|
|
||||||
GFile *root;
|
|
||||||
char *mount_path;
|
|
||||||
|
|
||||||
mount = g_volume_get_mount (volume);
|
g_free (id);
|
||||||
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);
|
|
||||||
|
|
||||||
outstanding_mounts--;
|
outstanding_mounts--;
|
||||||
|
|
||||||
@ -988,7 +972,7 @@ mount_with_device_file_cb (GObject *object,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mount_with_device_file (const char *device_file)
|
mount_with_id (const char *id)
|
||||||
{
|
{
|
||||||
GList *volumes;
|
GList *volumes;
|
||||||
GList *l;
|
GList *l;
|
||||||
@ -997,10 +981,12 @@ mount_with_device_file (const char *device_file)
|
|||||||
for (l = volumes; l != NULL; l = l->next)
|
for (l = volumes; l != NULL; l = l->next)
|
||||||
{
|
{
|
||||||
GVolume *volume = G_VOLUME (l->data);
|
GVolume *volume = G_VOLUME (l->data);
|
||||||
gchar *id;
|
gchar *device;
|
||||||
|
gchar *uuid;
|
||||||
|
|
||||||
id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
|
device = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
|
||||||
if (g_strcmp0 (id, device_file) == 0)
|
uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID);
|
||||||
|
if (g_strcmp0 (device, id) == 0 || g_strcmp0 (uuid, id) == 0)
|
||||||
{
|
{
|
||||||
GMountOperation *op;
|
GMountOperation *op;
|
||||||
|
|
||||||
@ -1011,20 +997,21 @@ mount_with_device_file (const char *device_file)
|
|||||||
op,
|
op,
|
||||||
NULL,
|
NULL,
|
||||||
mount_with_device_file_cb,
|
mount_with_device_file_cb,
|
||||||
id);
|
g_strdup (id));
|
||||||
|
|
||||||
g_object_unref (op);
|
g_object_unref (op);
|
||||||
|
|
||||||
outstanding_mounts++;
|
outstanding_mounts++;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
g_free (id);
|
g_free (device);
|
||||||
|
g_free (uuid);
|
||||||
}
|
}
|
||||||
g_list_free_full (volumes, g_object_unref);
|
g_list_free_full (volumes, g_object_unref);
|
||||||
|
|
||||||
if (outstanding_mounts == 0)
|
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;
|
success = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1236,8 +1223,8 @@ handle_mount (int argc, char *argv[], gboolean do_help)
|
|||||||
|
|
||||||
if (mount_list)
|
if (mount_list)
|
||||||
list_monitor_items ();
|
list_monitor_items ();
|
||||||
else if (mount_device_file != NULL)
|
else if (mount_id != NULL)
|
||||||
mount_with_device_file (mount_device_file);
|
mount_with_id (mount_id);
|
||||||
else if (stop_device_file)
|
else if (stop_device_file)
|
||||||
stop_with_device_file (stop_device_file);
|
stop_with_device_file (stop_device_file);
|
||||||
else if (unmount_scheme != NULL)
|
else if (unmount_scheme != NULL)
|
||||||
|
Loading…
Reference in New Issue
Block a user