gio: Update mounts after g_volume_mount

The documentation claims that g_volume_get_mount should	succeed	after
g_volume_mount. Let's update mounts before releasing g_volume_mount to
be sure that the mount is added to the corresponding volume. The same
is done in GVfsUDisks2VolumeMonitor.

https://gitlab.gnome.org/GNOME/glib/issues/1458
This commit is contained in:
Ondrej Holy 2018-07-30 15:26:31 +02:00
parent e5f87342e8
commit 9b6b282e0a
3 changed files with 19 additions and 10 deletions

View File

@ -274,6 +274,7 @@ eject_mount_done (GObject *source,
GTask *task = user_data; GTask *task = user_data;
GError *error = NULL; GError *error = NULL;
gchar *stderr_str; gchar *stderr_str;
GUnixVolume *unix_volume;
if (!g_subprocess_communicate_utf8_finish (subprocess, result, NULL, &stderr_str, &error)) 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 */ /* ...but bad exit code */
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, "%s", stderr_str); g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, "%s", stderr_str);
else else
{
/* ...and successful exit code */ /* ...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_task_return_boolean (task, TRUE);
}
g_free (stderr_str); 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; 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 static void
mountpoints_changed (GUnixMountMonitor *mount_monitor, mountpoints_changed (GUnixMountMonitor *mount_monitor,
gpointer user_data) gpointer user_data)
{ {
GUnixVolumeMonitor *unix_monitor = user_data; GUnixVolumeMonitor *unix_monitor = user_data;
/* Update both to make sure volumes are created before mounts */ _g_unix_volume_monitor_update (unix_monitor);
update_volumes (unix_monitor);
update_mounts (unix_monitor);
} }
static void static void
@ -200,9 +206,7 @@ mounts_changed (GUnixMountMonitor *mount_monitor,
{ {
GUnixVolumeMonitor *unix_monitor = user_data; GUnixVolumeMonitor *unix_monitor = user_data;
/* Update both to make sure volumes are created before mounts */ _g_unix_volume_monitor_update (unix_monitor);
update_volumes (unix_monitor);
update_mounts (unix_monitor);
} }
static void static void
@ -219,8 +223,7 @@ g_unix_volume_monitor_init (GUnixVolumeMonitor *unix_monitor)
"mountpoints-changed", G_CALLBACK (mountpoints_changed), "mountpoints-changed", G_CALLBACK (mountpoints_changed),
unix_monitor); unix_monitor);
update_volumes (unix_monitor); _g_unix_volume_monitor_update (unix_monitor);
update_mounts (unix_monitor);
} }
GVolumeMonitor * GVolumeMonitor *

View File

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