[PATCH] eject improvement, again - Nautilus bugzilla # 151840
- From: Magnus Damm <magnus damm gmail com>
- To: "gnome-vfs-list gnome org" <gnome-vfs-list gnome org>
- Cc: Alexander Larsson <alexl redhat com>
- Subject: [PATCH] eject improvement, again - Nautilus bugzilla # 151840
- Date: Sun, 9 Jan 2005 23:33:21 +0100
Hello,
The attached patch makes it possible to eject umounted volumes. I
generated the patch against gnome-vfs-2.8.1, but it applies against
CVS of today. The patch is tested with what I happen to have installed
on my Apple box (gnome-vfs-2.8.3) and everything seems to work fine.
The only change since last release is a fix to cope with bugzilla
#143569.
Please apply. Thanks.
/ magnus
--- gnome-vfs-2.8.1/libgnomevfs/gnome-vfs-volume-ops.c 2004-12-03 17:46:37.000000000 +0100
+++ gnome-vfs-2.8.1-eject/libgnomevfs/gnome-vfs-volume-ops.c 2005-01-09 22:54:51.000000000 +0100
@@ -88,6 +88,7 @@
char *device_path;
GnomeVFSDeviceType device_type;
gboolean should_mount;
+ gboolean should_unmount;
gboolean should_eject;
GnomeVFSVolumeOpCallback callback;
gpointer user_data;
@@ -222,7 +223,11 @@
info = arg;
- if (info != NULL) {
+ info->succeeded = TRUE;
+ info->error_message = NULL;
+ info->detailed_error_message = NULL;
+
+ if (info->should_mount || info->should_unmount) {
error = NULL;
if (g_spawn_sync (NULL,
info->argv,
@@ -233,11 +238,7 @@
&standard_error,
&exit_status,
&error)) {
- if (exit_status == 0) {
- info->succeeded = TRUE;
- info->error_message = NULL;
- info->detailed_error_message = NULL;
- } else {
+ if (exit_status != 0) {
info->succeeded = FALSE;
if (info->should_mount) {
info->error_message = generate_mount_error_message (standard_error,
@@ -278,6 +279,7 @@
argv[1] = info->device_path?info->device_path:info->mount_point;
#endif
+ error = NULL;
if (g_spawn_sync (NULL,
argv,
NULL,
@@ -286,8 +288,15 @@
NULL, &standard_error,
&exit_status,
&error)) {
- if (exit_status != 0 &&
- info->succeeded) {
+
+ if (info->succeeded == FALSE) {
+ g_free(info->error_message);
+ info->error_message = NULL;
+ g_free(info->detailed_error_message);
+ info->detailed_error_message = NULL;
+ }
+
+ if (exit_status != 0) {
info->succeeded = FALSE;
info->error_message = g_strdup (_("Unable to eject media"));
info->detailed_error_message = g_strdup (standard_error);
@@ -295,6 +304,8 @@
/* If the eject succeed then ignore the previous unmount error (if any) */
info->succeeded = TRUE;
}
+
+ g_free (standard_error);
} else {
/* Spawn failure */
if (info->succeeded) {
@@ -304,7 +315,6 @@
}
g_error_free (error);
}
- g_free (standard_error);
}
g_idle_add (report_mount_result, info);
@@ -320,11 +330,13 @@
const char *device_path,
GnomeVFSDeviceType device_type,
gboolean should_mount,
+ gboolean should_unmount,
gboolean should_eject,
GnomeVFSVolumeOpCallback callback,
gpointer user_data)
{
- const char *command;
+ const char *command = NULL;
+ const char *argument = NULL;
MountThreadInfo *mount_info;
pthread_t mount_thread;
const char *name;
@@ -343,30 +355,36 @@
#endif
if (should_mount) {
- command = find_command (MOUNT_COMMAND);
- } else {
- command = find_command (UMOUNT_COMMAND);
- }
-
- mount_info = g_new0 (MountThreadInfo, 1);
- i = 0;
- mount_info->argv[i++] = g_strdup (command);
- if (should_mount) {
+ command = find_command (MOUNT_COMMAND);
#ifdef MOUNT_ARGUMENT
- mount_info->argv[i++] = g_strdup (MOUNT_ARGUMENT);
+ argument = MOUNT_ARGUMENT;
#endif
- } else {
+ }
+
+ if (should_unmount) {
+ command = find_command (UMOUNT_COMMAND);
#ifdef UNMOUNT_ARGUMENT
- mount_info->argv[i++] = g_strdup (UNMOUNT_ARGUMENT);
+ argument = UNMOUNT_ARGUMENT;
#endif
+ }
+
+ mount_info = g_new0 (MountThreadInfo, 1);
+
+ if (command) {
+ i = 0;
+ mount_info->argv[i++] = g_strdup (command);
+ if (argument) {
+ mount_info->argv[i++] = g_strdup (argument);
+ }
+ mount_info->argv[i++] = g_strdup (name);
+ mount_info->argv[i++] = NULL;
}
- mount_info->argv[i++] = g_strdup (name);
- mount_info->argv[i++] = NULL;
mount_info->mount_point = g_strdup (mount_point);
mount_info->device_path = g_strdup (device_path);
mount_info->device_type = device_type;
mount_info->should_mount = should_mount;
+ mount_info->should_unmount = should_unmount;
mount_info->should_eject = should_eject;
mount_info->callback = callback;
mount_info->user_data = user_data;
@@ -513,7 +531,7 @@
mount_unmount_operation (mount_path,
device_path,
gnome_vfs_volume_get_device_type (volume),
- FALSE, FALSE,
+ FALSE, TRUE, FALSE,
callback, user_data);
g_free (mount_path);
g_free (device_path);
@@ -552,7 +570,7 @@
mount_unmount_operation (mount_path,
device_path,
gnome_vfs_volume_get_device_type (volume),
- FALSE, TRUE,
+ FALSE, TRUE, TRUE,
callback, user_data);
g_free (mount_path);
g_free (device_path);
@@ -585,7 +603,7 @@
mount_unmount_operation (mount_path,
device_path,
GNOME_VFS_DEVICE_TYPE_UNKNOWN,
- TRUE, FALSE,
+ TRUE, FALSE, FALSE,
callback, user_data);
g_free (mount_path);
g_free (device_path);
@@ -650,7 +668,7 @@
/* Check to see if this is the last volume */
/* If not simply unmount it */
/* If so the eject the media along with the unmount */
- if (current_vol != NULL) {
+ if (current_vol->next != NULL) {
gnome_vfs_volume_unmount (vol,
callback,
user_data);
@@ -662,6 +680,22 @@
}
+ if (vol_list == NULL) { /* no mounted volumes */
+ char *mount_path, *device_path, *uri;
+
+ uri = gnome_vfs_drive_get_activation_uri (drive);
+ mount_path = gnome_vfs_get_local_path_from_uri (uri);
+ g_free (uri);
+ device_path = gnome_vfs_drive_get_device_path (drive);
+ mount_unmount_operation (mount_path,
+ device_path,
+ GNOME_VFS_DEVICE_TYPE_UNKNOWN,
+ FALSE, FALSE, TRUE,
+ callback, user_data);
+ g_free (mount_path);
+ g_free (device_path);
+ }
+
gnome_vfs_drive_volume_list_free (vol_list);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]