mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-09 19:06:15 +01:00
Merge branch 'wip/oholy/gio-mount-stop' into 'master'
gio-tool: Add support for stopping drives See merge request GNOME/glib!17
This commit is contained in:
commit
137ae066fe
@ -50,6 +50,7 @@ static gboolean extra_detail = FALSE;
|
||||
static gboolean mount_monitor = FALSE;
|
||||
static const char *unmount_scheme = NULL;
|
||||
static const char *mount_device_file = NULL;
|
||||
static const char *stop_device_file = NULL;
|
||||
static gboolean success = TRUE;
|
||||
|
||||
|
||||
@ -59,6 +60,7 @@ static const GOptionEntry entries[] =
|
||||
{ "device", 'd', 0, G_OPTION_ARG_STRING, &mount_device_file, N_("Mount volume with device file"), N_("DEVICE") },
|
||||
{ "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") },
|
||||
{ "unmount-scheme", 's', 0, G_OPTION_ARG_STRING, &unmount_scheme, N_("Unmount all mounts with the given scheme"), N_("SCHEME") },
|
||||
{ "force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Ignore outstanding file operations when unmounting or ejecting"), NULL },
|
||||
{ "anonymous", 'a', 0, G_OPTION_ARG_NONE, &anonymous, N_("Use an anonymous user when authenticating"), NULL },
|
||||
@ -252,6 +254,8 @@ mount_mountable_done_cb (GObject *object,
|
||||
else
|
||||
g_object_unref (target);
|
||||
|
||||
g_object_unref (op);
|
||||
|
||||
outstanding_mounts--;
|
||||
|
||||
if (outstanding_mounts == 0)
|
||||
@ -280,6 +284,8 @@ mount_done_cb (GObject *object,
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_object_unref (op);
|
||||
|
||||
outstanding_mounts--;
|
||||
|
||||
if (outstanding_mounts == 0)
|
||||
@ -436,6 +442,76 @@ eject (GFile *file)
|
||||
outstanding_mounts++;
|
||||
}
|
||||
|
||||
static void
|
||||
stop_with_device_file_cb (GObject *object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gchar *device_path = user_data;
|
||||
|
||||
if (!g_drive_stop_finish (G_DRIVE (object), res, &error))
|
||||
{
|
||||
print_error ("%s: %s", device_path, error->message);
|
||||
g_error_free (error);
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
g_free (device_path);
|
||||
|
||||
outstanding_mounts--;
|
||||
|
||||
if (outstanding_mounts == 0)
|
||||
g_main_loop_quit (main_loop);
|
||||
}
|
||||
|
||||
static void
|
||||
stop_with_device_file (const char *device_file)
|
||||
{
|
||||
GVolumeMonitor *volume_monitor;
|
||||
GList *drives;
|
||||
GList *l;
|
||||
|
||||
volume_monitor = g_volume_monitor_get ();
|
||||
|
||||
drives = g_volume_monitor_get_connected_drives (volume_monitor);
|
||||
for (l = drives; l != NULL; l = l->next)
|
||||
{
|
||||
GDrive *drive = G_DRIVE (l->data);
|
||||
gchar *id;
|
||||
|
||||
id = g_drive_get_identifier (drive, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
|
||||
if (g_strcmp0 (id, device_file) == 0)
|
||||
{
|
||||
GMountOperation *op;
|
||||
GMountUnmountFlags flags;
|
||||
|
||||
op = new_mount_op ();
|
||||
flags = force ? G_MOUNT_UNMOUNT_FORCE : G_MOUNT_UNMOUNT_NONE;
|
||||
g_drive_stop (drive,
|
||||
flags,
|
||||
op,
|
||||
NULL,
|
||||
stop_with_device_file_cb,
|
||||
g_steal_pointer (&id));
|
||||
g_object_unref (op);
|
||||
|
||||
outstanding_mounts++;
|
||||
}
|
||||
|
||||
g_free (id);
|
||||
}
|
||||
g_list_free_full (drives, g_object_unref);
|
||||
|
||||
if (outstanding_mounts == 0)
|
||||
{
|
||||
print_error ("%s: %s", device_file, _("No drive for device file"));
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
g_object_unref (volume_monitor);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
iterate_gmain_timeout_function (gpointer data)
|
||||
{
|
||||
@ -938,6 +1014,8 @@ mount_with_device_file (const char *device_file)
|
||||
mount_with_device_file_cb,
|
||||
id);
|
||||
|
||||
g_object_unref (op);
|
||||
|
||||
outstanding_mounts++;
|
||||
}
|
||||
else
|
||||
@ -1166,6 +1244,8 @@ handle_mount (int argc, char *argv[], gboolean do_help)
|
||||
list_monitor_items ();
|
||||
else if (mount_device_file != NULL)
|
||||
mount_with_device_file (mount_device_file);
|
||||
else if (stop_device_file)
|
||||
stop_with_device_file (stop_device_file);
|
||||
else if (unmount_scheme != NULL)
|
||||
unmount_all_with_scheme (unmount_scheme);
|
||||
else if (mount_monitor)
|
||||
|
Loading…
Reference in New Issue
Block a user