Patch: fix 100% cpu when mime-info files are updated



The following patch fixes 100% cpu usage in nautilus (and probably other
apps) when mime-info files are modified. To trigger it, simply run
"touch /usr/share/mime-info/*" and see nautilus (and maybe your desktop)
frozen for a long time :)) This bug has been here since GNOME 2.2 :((

http://qa.mandrakesoft.com/show_bug.cgi?id=2457

Since I'm the patch author, I can't give my r-t approval on it :)

Patch was reviewed by Alex.
-- 
Frederic Crozat <fcrozat mandrakesoft com>
Mandrakesoft
--- gnome-vfs-2.3.8/libgnomevfs/gnome-vfs-mime-monitor.c.mimeupdate	2002-12-20 22:15:03.000000000 +0100
+++ gnome-vfs-2.3.8/libgnomevfs/gnome-vfs-mime-monitor.c	2003-09-02 10:36:12.000000000 +0200
@@ -55,6 +55,8 @@
 	/* The hoops I jump through */
 	MonitorCallbackData *gnome_callback_data;
 	MonitorCallbackData *local_callback_data;
+
+	guint mime_update_tag;
 };
 
 
@@ -124,6 +126,16 @@
 	g_free (mime_dir);
 }
 
+static gboolean
+mime_dir_emit_data_changed (gpointer user_data)
+{
+	MonitorCallbackData *monitor_callback_data = (MonitorCallbackData *)user_data;
+
+	_gnome_vfs_mime_monitor_emit_data_changed (monitor_callback_data->monitor);
+	monitor_callback_data->monitor->priv->mime_update_tag = 0;
+
+	return FALSE;	
+}
 
 static void
 mime_dir_changed_callback (GnomeVFSMonitorHandle    *handle,
@@ -138,8 +150,12 @@
 		_gnome_vfs_mime_info_mark_gnome_mime_dir_dirty ();
 	else if (monitor_callback_data->type == LOCAL_MIME_DIR)
 		_gnome_vfs_mime_info_mark_user_mime_dir_dirty ();
-		
-	_gnome_vfs_mime_monitor_emit_data_changed (monitor_callback_data->monitor);
+
+	if (monitor_callback_data->monitor->priv->mime_update_tag == 0) {
+               monitor_callback_data->monitor->priv->mime_update_tag = 
+		       g_timeout_add (100, mime_dir_emit_data_changed, user_data);
+       	}
+
 }
 
 static void
@@ -147,6 +163,9 @@
 {
 	gnome_vfs_monitor_cancel (GNOME_VFS_MIME_MONITOR (object)->priv->global_handle);
 	gnome_vfs_monitor_cancel (GNOME_VFS_MIME_MONITOR (object)->priv->local_handle);
+	if (GNOME_VFS_MIME_MONITOR (object)->priv->mime_update_tag != 0) {
+		g_source_remove (GNOME_VFS_MIME_MONITOR (object)->priv->mime_update_tag);
+	}
 	g_free (GNOME_VFS_MIME_MONITOR (object)->priv->gnome_callback_data);
 	g_free (GNOME_VFS_MIME_MONITOR (object)->priv->local_callback_data);
 	g_free (GNOME_VFS_MIME_MONITOR (object)->priv);


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