Merge branch 'wip/oholy/update-mounts' into 'master'

Be sure that g_volume_get_mount succeed after g_volume_mount

See merge request GNOME/glib!217
This commit is contained in:
Philip Withnall 2018-08-02 15:40:50 +00:00
commit 7f5296d055
4 changed files with 24 additions and 34 deletions

View File

@ -39,6 +39,7 @@ typedef enum {
static int outstanding_mounts = 0;
static GMainLoop *main_loop;
static GVolumeMonitor *volume_monitor;
static gboolean mount_mountable = FALSE;
static gboolean mount_unmount = FALSE;
@ -484,12 +485,9 @@ stop_with_device_file_cb (GObject *object,
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)
{
@ -524,8 +522,6 @@ stop_with_device_file (const char *device_file)
print_error ("%s: %s", device_file, _("No drive for device file"));
success = FALSE;
}
g_object_unref (volume_monitor);
}
static gboolean
@ -905,11 +901,8 @@ list_drives (GList *drives,
static void
list_monitor_items (void)
{
GVolumeMonitor *volume_monitor;
GList *drives, *volumes, *mounts;
volume_monitor = g_volume_monitor_get();
/* populate gvfs network mounts */
iterate_gmain();
@ -924,19 +917,14 @@ list_monitor_items (void)
mounts = g_volume_monitor_get_mounts (volume_monitor);
list_mounts (mounts, 0, TRUE);
g_list_free_full (mounts, g_object_unref);
g_object_unref (volume_monitor);
}
static void
unmount_all_with_scheme (const char *scheme)
{
GVolumeMonitor *volume_monitor;
GList *mounts;
GList *l;
volume_monitor = g_volume_monitor_get();
/* populate gvfs network mounts */
iterate_gmain();
@ -952,8 +940,6 @@ unmount_all_with_scheme (const char *scheme)
g_object_unref (root);
}
g_list_free_full (mounts, g_object_unref);
g_object_unref (volume_monitor);
}
static void
@ -1004,12 +990,9 @@ mount_with_device_file_cb (GObject *object,
static void
mount_with_device_file (const char *device_file)
{
GVolumeMonitor *volume_monitor;
GList *volumes;
GList *l;
volume_monitor = g_volume_monitor_get();
volumes = g_volume_monitor_get_volumes (volume_monitor);
for (l = volumes; l != NULL; l = l->next)
{
@ -1044,8 +1027,6 @@ mount_with_device_file (const char *device_file)
print_error ("%s: %s", device_file, _("No volume for device file"));
success = FALSE;
}
g_object_unref (volume_monitor);
}
static void
@ -1199,10 +1180,6 @@ monitor_drive_eject_button (GVolumeMonitor *volume_monitor, GDrive *drive)
static void
monitor (void)
{
GVolumeMonitor *volume_monitor;
volume_monitor = g_volume_monitor_get ();
g_signal_connect (volume_monitor, "mount-added", (GCallback) monitor_mount_added, NULL);
g_signal_connect (volume_monitor, "mount-removed", (GCallback) monitor_mount_removed, NULL);
g_signal_connect (volume_monitor, "mount-changed", (GCallback) monitor_mount_changed, NULL);
@ -1255,6 +1232,7 @@ handle_mount (int argc, char *argv[], gboolean do_help)
}
main_loop = g_main_loop_new (NULL, FALSE);
volume_monitor = g_volume_monitor_get ();
if (mount_list)
list_monitor_items ();
@ -1284,6 +1262,7 @@ handle_mount (int argc, char *argv[], gboolean do_help)
{
show_help (context, _("No locations given"));
g_option_context_free (context);
g_object_unref (volume_monitor);
return 1;
}
@ -1292,5 +1271,7 @@ handle_mount (int argc, char *argv[], gboolean do_help)
if (outstanding_mounts > 0)
g_main_loop_run (main_loop);
g_object_unref (volume_monitor);
return success ? 0 : 2;
}

View File

@ -274,6 +274,7 @@ eject_mount_done (GObject *source,
GTask *task = user_data;
GError *error = NULL;
gchar *stderr_str;
GUnixVolume *unix_volume;
if (!g_subprocess_communicate_utf8_finish (subprocess, result, NULL, &stderr_str, &error))
{
@ -286,8 +287,12 @@ eject_mount_done (GObject *source,
/* ...but bad exit code */
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, "%s", stderr_str);
else
/* ...and successful exit code */
g_task_return_boolean (task, TRUE);
{
/* ...and successful exit code */
unix_volume = G_UNIX_VOLUME (g_task_get_source_object (task));
_g_unix_volume_monitor_update (G_UNIX_VOLUME_MONITOR (unix_volume->volume_monitor));
g_task_return_boolean (task, TRUE);
}
g_free (stderr_str);
}

View File

@ -183,15 +183,21 @@ g_unix_volume_monitor_class_init (GUnixVolumeMonitorClass *klass)
native_class->get_mount_for_mount_path = get_mount_for_mount_path;
}
void
_g_unix_volume_monitor_update (GUnixVolumeMonitor *unix_monitor)
{
/* Update both to make sure volumes are created before mounts */
update_volumes (unix_monitor);
update_mounts (unix_monitor);
}
static void
mountpoints_changed (GUnixMountMonitor *mount_monitor,
gpointer user_data)
{
GUnixVolumeMonitor *unix_monitor = user_data;
/* Update both to make sure volumes are created before mounts */
update_volumes (unix_monitor);
update_mounts (unix_monitor);
_g_unix_volume_monitor_update (unix_monitor);
}
static void
@ -200,9 +206,7 @@ mounts_changed (GUnixMountMonitor *mount_monitor,
{
GUnixVolumeMonitor *unix_monitor = user_data;
/* Update both to make sure volumes are created before mounts */
update_volumes (unix_monitor);
update_mounts (unix_monitor);
_g_unix_volume_monitor_update (unix_monitor);
}
static void
@ -219,8 +223,7 @@ g_unix_volume_monitor_init (GUnixVolumeMonitor *unix_monitor)
"mountpoints-changed", G_CALLBACK (mountpoints_changed),
unix_monitor);
update_volumes (unix_monitor);
update_mounts (unix_monitor);
_g_unix_volume_monitor_update (unix_monitor);
}
GVolumeMonitor *

View File

@ -55,6 +55,7 @@ GType _g_unix_volume_monitor_get_type (void) G_GN
GVolumeMonitor * _g_unix_volume_monitor_new (void);
GUnixVolume * _g_unix_volume_monitor_lookup_volume_for_mount_path (GUnixVolumeMonitor *monitor,
const char *mount_path);
void _g_unix_volume_monitor_update (GUnixVolumeMonitor *monitor);
G_END_DECLS