mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-11-04 18:18:56 +01:00
gio-tool: Hold GVolumeMonitor reference during operations
Releasing GVolumeMonitor before g_volume_mount finish cause that
g_volume_get_mount returns NULL, because the mount is not correctly
propagated to the volume.
(Backported from commit 88b8ebb5dd with
minor merge conflicts.)
https://gitlab.gnome.org/GNOME/glib/issues/1458
This commit is contained in:
committed by
Philip Withnall
parent
f9ab355896
commit
2c1aee1963
@@ -39,6 +39,7 @@ typedef enum {
|
|||||||
|
|
||||||
static int outstanding_mounts = 0;
|
static int outstanding_mounts = 0;
|
||||||
static GMainLoop *main_loop;
|
static GMainLoop *main_loop;
|
||||||
|
static GVolumeMonitor *volume_monitor;
|
||||||
|
|
||||||
static gboolean mount_mountable = FALSE;
|
static gboolean mount_mountable = FALSE;
|
||||||
static gboolean mount_unmount = FALSE;
|
static gboolean mount_unmount = FALSE;
|
||||||
@@ -813,11 +814,8 @@ list_drives (GList *drives,
|
|||||||
static void
|
static void
|
||||||
list_monitor_items (void)
|
list_monitor_items (void)
|
||||||
{
|
{
|
||||||
GVolumeMonitor *volume_monitor;
|
|
||||||
GList *drives, *volumes, *mounts;
|
GList *drives, *volumes, *mounts;
|
||||||
|
|
||||||
volume_monitor = g_volume_monitor_get();
|
|
||||||
|
|
||||||
/* populate gvfs network mounts */
|
/* populate gvfs network mounts */
|
||||||
iterate_gmain();
|
iterate_gmain();
|
||||||
|
|
||||||
@@ -832,19 +830,14 @@ list_monitor_items (void)
|
|||||||
mounts = g_volume_monitor_get_mounts (volume_monitor);
|
mounts = g_volume_monitor_get_mounts (volume_monitor);
|
||||||
list_mounts (mounts, 0, TRUE);
|
list_mounts (mounts, 0, TRUE);
|
||||||
g_list_free_full (mounts, g_object_unref);
|
g_list_free_full (mounts, g_object_unref);
|
||||||
|
|
||||||
g_object_unref (volume_monitor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
unmount_all_with_scheme (const char *scheme)
|
unmount_all_with_scheme (const char *scheme)
|
||||||
{
|
{
|
||||||
GVolumeMonitor *volume_monitor;
|
|
||||||
GList *mounts;
|
GList *mounts;
|
||||||
GList *l;
|
GList *l;
|
||||||
|
|
||||||
volume_monitor = g_volume_monitor_get();
|
|
||||||
|
|
||||||
/* populate gvfs network mounts */
|
/* populate gvfs network mounts */
|
||||||
iterate_gmain();
|
iterate_gmain();
|
||||||
|
|
||||||
@@ -860,8 +853,6 @@ unmount_all_with_scheme (const char *scheme)
|
|||||||
g_object_unref (root);
|
g_object_unref (root);
|
||||||
}
|
}
|
||||||
g_list_free_full (mounts, g_object_unref);
|
g_list_free_full (mounts, g_object_unref);
|
||||||
|
|
||||||
g_object_unref (volume_monitor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -912,12 +903,9 @@ mount_with_device_file_cb (GObject *object,
|
|||||||
static void
|
static void
|
||||||
mount_with_device_file (const char *device_file)
|
mount_with_device_file (const char *device_file)
|
||||||
{
|
{
|
||||||
GVolumeMonitor *volume_monitor;
|
|
||||||
GList *volumes;
|
GList *volumes;
|
||||||
GList *l;
|
GList *l;
|
||||||
|
|
||||||
volume_monitor = g_volume_monitor_get();
|
|
||||||
|
|
||||||
volumes = g_volume_monitor_get_volumes (volume_monitor);
|
volumes = g_volume_monitor_get_volumes (volume_monitor);
|
||||||
for (l = volumes; l != NULL; l = l->next)
|
for (l = volumes; l != NULL; l = l->next)
|
||||||
{
|
{
|
||||||
@@ -950,8 +938,6 @@ mount_with_device_file (const char *device_file)
|
|||||||
print_error ("%s: %s", device_file, _("No volume for device file"));
|
print_error ("%s: %s", device_file, _("No volume for device file"));
|
||||||
success = FALSE;
|
success = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (volume_monitor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1105,10 +1091,6 @@ monitor_drive_eject_button (GVolumeMonitor *volume_monitor, GDrive *drive)
|
|||||||
static void
|
static void
|
||||||
monitor (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-added", (GCallback) monitor_mount_added, NULL);
|
||||||
g_signal_connect (volume_monitor, "mount-removed", (GCallback) monitor_mount_removed, 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);
|
g_signal_connect (volume_monitor, "mount-changed", (GCallback) monitor_mount_changed, NULL);
|
||||||
@@ -1163,6 +1145,7 @@ handle_mount (int argc, char *argv[], gboolean do_help)
|
|||||||
g_option_context_free (context);
|
g_option_context_free (context);
|
||||||
|
|
||||||
main_loop = g_main_loop_new (NULL, FALSE);
|
main_loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
volume_monitor = g_volume_monitor_get ();
|
||||||
|
|
||||||
if (mount_list)
|
if (mount_list)
|
||||||
list_monitor_items ();
|
list_monitor_items ();
|
||||||
@@ -1190,5 +1173,7 @@ handle_mount (int argc, char *argv[], gboolean do_help)
|
|||||||
if (outstanding_mounts > 0)
|
if (outstanding_mounts > 0)
|
||||||
g_main_loop_run (main_loop);
|
g_main_loop_run (main_loop);
|
||||||
|
|
||||||
|
g_object_unref (volume_monitor);
|
||||||
|
|
||||||
return success ? 0 : 2;
|
return success ? 0 : 2;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user