brasero r1391 - in trunk: . src



Author: philippr
Date: Sat Oct 18 11:43:24 2008
New Revision: 1391
URL: http://svn.gnome.org/viewvc/brasero?rev=1391&view=rev

Log:
	Be a little more patient and understanding when we eject media

	* src/brasero-file-monitor.c
	(brasero_file_monitor_start_monitoring_real),
	(brasero_file_monitor_single_file):
	* src/burn-volume-obj.c (brasero_volume_eject):
	* src/burn.c (brasero_burn_eject), (brasero_burn_eject_dest_media),
	(brasero_burn_eject_src_media):


Modified:
   trunk/ChangeLog
   trunk/src/brasero-file-monitor.c
   trunk/src/burn-volume-obj.c
   trunk/src/burn.c

Modified: trunk/src/brasero-file-monitor.c
==============================================================================
--- trunk/src/brasero-file-monitor.c	(original)
+++ trunk/src/brasero-file-monitor.c	Sat Oct 18 11:43:24 2008
@@ -595,6 +595,7 @@
 	       IN_DELETE_SELF |
 	       IN_MOVE_SELF;
 
+	/* NOTE: always return the same wd when we ask for the same file */
 	wd = inotify_add_watch (dev_fd, path, mask);
 	if (wd == -1) {
 		BRASERO_BURN_LOG ("ERROR creating watch for local file %s : %s\n",
@@ -642,6 +643,7 @@
 	data->callback_data = callback_data;
 	BRASERO_GET_BASENAME_FOR_DISPLAY (uri, data->name);
 
+	/* inotify always return the same wd for the same file */
 	list = g_hash_table_lookup (priv->files, GINT_TO_POINTER (wd));
 	list = g_slist_prepend (list, data);
 	g_hash_table_insert (priv->files,

Modified: trunk/src/burn-volume-obj.c
==============================================================================
--- trunk/src/burn-volume-obj.c	(original)
+++ trunk/src/burn-volume-obj.c	Sat Oct 18 11:43:24 2008
@@ -597,6 +597,7 @@
 		      GError **error)
 {
 	GDrive *gdrive;
+	GVolume *volume;
 	gboolean result;
 	BraseroVolumePrivate *priv;
 
@@ -609,30 +610,13 @@
 
 	gdrive = brasero_volume_get_gdrive (self);
 	if (!gdrive) {
-		GVolume *volume;
-
 		BRASERO_BURN_LOG ("No GDrive");
-
-		/* last resort */
-		volume = brasero_volume_get_gvolume (self);
-
-		result = brasero_volume_eject_gvolume (self, wait, volume, error);
-		g_object_unref (volume);
-		return result;
+		goto last_resort;
 	}
 
 	if (!g_drive_can_eject (gdrive)) {
-		GVolume *volume;
-
 		BRASERO_BURN_LOG ("GDrive can't eject");
-
-		/* last resort */
-		volume = brasero_volume_get_gvolume (self);
-
-		result = brasero_volume_eject_gvolume (self, wait, volume, error);
-		g_object_unref (volume);
-		g_object_unref (gdrive);
-		return result;
+		goto last_resort;
 	}
 
 	if (wait) {
@@ -670,6 +654,18 @@
 
 	g_object_unref (gdrive);
 	return result;
+
+last_resort:
+
+	/* last resort */
+	volume = brasero_volume_get_gvolume (self);
+	result = brasero_volume_eject_gvolume (self, wait, volume, error);
+	g_object_unref (volume);
+
+	if (gdrive)
+		g_object_unref (gdrive);
+
+	return result;
 }
 
 void

Modified: trunk/src/burn.c
==============================================================================
--- trunk/src/burn.c	(original)
+++ trunk/src/burn.c	Sat Oct 18 11:43:24 2008
@@ -128,7 +128,7 @@
 
 #define BRASERO_BURN_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_BURN, BraseroBurnPrivate))
 
-#define MAX_EJECT_WAIT_TIME	20000
+#define MAX_EJECT_ATTEMPTS	5
 #define MAX_MOUNT_ATTEMPTS	20
 #define MOUNT_TIMEOUT		500
 
@@ -300,10 +300,56 @@
 }
 
 static BraseroBurnResult
+brasero_burn_eject (BraseroBurn *self,
+		    BraseroDrive *drive,
+		    GError **error)
+{
+	BraseroMedium *medium;
+	guint counter = 0;
+
+	medium = brasero_drive_get_medium (drive);
+	brasero_volume_eject (BRASERO_VOLUME (medium), TRUE, error);
+
+	/* sleep some time and see what happened */
+	brasero_burn_sleep (self, 500);
+	medium = brasero_drive_get_medium (drive);
+
+	/* Retry several times, since sometimes the drives are really busy */
+	while (medium && brasero_medium_get_status (medium) != BRASERO_MEDIUM_NONE) {
+		counter ++;
+		if (counter > MAX_EJECT_ATTEMPTS) {
+			gchar *name;
+
+			BRASERO_BURN_LOG ("Max attempts reached at ejecting");
+
+			/* FIXME: it'd be better if we asked the user to do it
+			 * manually */
+			name = brasero_drive_get_display_name (drive);
+			if (error && !(*error))
+				g_set_error (error,
+					     BRASERO_BURN_ERROR,
+					     BRASERO_BURN_ERROR_GENERAL,
+					     _("the media in %s can't be ejected"),
+					     name);
+			g_free (name);
+			return BRASERO_BURN_ERR;
+		}
+
+		BRASERO_BURN_LOG ("Retrying ejection");
+		brasero_volume_eject (BRASERO_VOLUME (medium), TRUE, error);
+		brasero_burn_sleep (self, 500);
+		medium = brasero_drive_get_medium (drive);
+	}
+
+	return BRASERO_BURN_OK;
+}
+
+static BraseroBurnResult
 brasero_burn_eject_dest_media (BraseroBurn *self,
 			       GError **error)
 {
 	BraseroBurnPrivate *priv;
+	BraseroBurnResult result;
 	BraseroMedium *medium;
 
 	priv = BRASERO_BURN_PRIVATE (self);
@@ -332,22 +378,8 @@
 		}
 	}
 
-	if (!brasero_volume_eject (BRASERO_VOLUME (medium), TRUE, NULL)) {
-		gchar *name;
-
-		name = brasero_drive_get_display_name (priv->dest);
-
-		g_set_error (error,
-			     BRASERO_BURN_ERROR,
-			     BRASERO_BURN_ERROR_GENERAL,
-			     _("the media in %s can't be ejected"),
-			     name);
-
-		g_free (name);
-
-		priv->dest = NULL;
-		return BRASERO_BURN_ERR;
-	}
+	result = brasero_burn_eject (self, priv->dest, error);
+	priv->dest = NULL;
 
 	return BRASERO_BURN_OK;
 }
@@ -357,6 +389,7 @@
 			      GError **error)
 {
 	BraseroBurnPrivate *priv;
+	BraseroBurnResult result;
 	BraseroMedium *medium;
 
 	priv = BRASERO_BURN_PRIVATE (self);
@@ -364,8 +397,8 @@
 	if (!priv->src)
 		return BRASERO_BURN_OK;
 
+	/* Release lock, unmount, ... */
 	medium = brasero_drive_get_medium (priv->src);
-
 	if (brasero_volume_is_mounted (BRASERO_VOLUME (medium))) {
 		BraseroBurnResult result;
 
@@ -390,28 +423,11 @@
 		}
 	}
 
-	brasero_volume_eject (BRASERO_VOLUME (medium), TRUE, error);
-	medium = brasero_drive_get_medium (priv->src);
-	if (medium && brasero_medium_get_status (medium) != BRASERO_MEDIUM_NONE) {
-		gchar *name;
-
-		name = brasero_drive_get_display_name (priv->src);
-
-		if (error && !(*error))
-			g_set_error (error,
-				     BRASERO_BURN_ERROR,
-				     BRASERO_BURN_ERROR_GENERAL,
-				     _("the media in %s can't be ejected"),
-				     name);
-
-		g_free (name);
-
-		priv->src = NULL;
-		return BRASERO_BURN_ERR;
-	}
-
+	/* and eject */
+	result = brasero_burn_eject (self, priv->src, error);
 	priv->src = NULL;
-	return BRASERO_BURN_OK;
+
+	return result;
 }
 
 static BraseroBurnResult



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]