diff --git a/ChangeLog b/ChangeLog index 7ab96fe9c5c3dc3e5dc3b0b5762fe010a014e72d..2a5974752cf92160bb9067485f9bcb78aa64de96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-11-27 Nick Schermer <nick@xfce.org> + + * thunar-vfs/thunar-vfs-monitor.c: Implement a simpler version of + the /proc and /dev ignore test. + * thunar-vfs/thunar-vfs-monitor.c: Use a GSList for the handles + since we only walk forwards. + 2008-11-27 Nick Schermer <nick@xfce.org> * plugins/thunar-sbr/thunar-sbr-case-renamer.c: Apply patch from diff --git a/thunar-vfs/thunar-vfs-monitor.c b/thunar-vfs/thunar-vfs-monitor.c index 3a00c9857f127bf3590c3e0d11eae0bf3d7313ac..6fdccc648cfe9520087d37a514bee0e74f5ed7ca 100644 --- a/thunar-vfs/thunar-vfs-monitor.c +++ b/thunar-vfs/thunar-vfs-monitor.c @@ -87,7 +87,7 @@ struct _ThunarVfsMonitor { GObject __parent__; - GList *handles; + GSList *handles; gint notifications_timer_id; ThunarVfsMonitorNotification *notifications; @@ -104,9 +104,6 @@ struct _ThunarVfsMonitor FAMConnection fc; gint fc_watch_id; #endif - - /* Excluded paths */ - GList *excluded_paths; }; struct _ThunarVfsMonitorHandle @@ -114,7 +111,7 @@ struct _ThunarVfsMonitorHandle ThunarVfsMonitorCallback callback; gpointer user_data; ThunarVfsPath *path; - gboolean directory; + guint directory : 1; #ifdef HAVE_LIBFAM FAMRequest fr; @@ -139,15 +136,6 @@ struct _ThunarVfsMonitorNotification static GObjectClass *thunar_vfs_monitor_parent_class; -static const gchar *excluded_paths[] = -{ -#ifdef HAVE_LINUX - "/proc/*", - "/dev/*", -#endif - NULL -}; - GType @@ -188,17 +176,10 @@ thunar_vfs_monitor_class_init (ThunarVfsMonitorClass *klass) static void thunar_vfs_monitor_init (ThunarVfsMonitor *monitor) { - gint i; - /* initialize the monitor */ monitor->cond = g_cond_new (); monitor->lock = g_mutex_new (); - /* Generate pattern specs for excluded paths */ - monitor->excluded_paths = NULL; - for (i = 0; excluded_paths[i] != NULL; ++i) - monitor->excluded_paths = g_list_append (monitor->excluded_paths, g_pattern_spec_new (excluded_paths[i])); - #ifdef HAVE_LIBFAM if (FAMOpen2 (&monitor->fc, PACKAGE_NAME) == 0) { @@ -228,16 +209,13 @@ thunar_vfs_monitor_finalize (GObject *object) { ThunarVfsMonitorNotification *notification; ThunarVfsMonitor *monitor = THUNAR_VFS_MONITOR (object); - GList *lp; + GSList *lp; #ifdef HAVE_LIBFAM if (monitor->fc_watch_id >= 0) thunar_vfs_monitor_fam_cancel (monitor); #endif - /* drop excluded path patterns */ - g_list_foreach (monitor->excluded_paths, (GFunc) g_pattern_spec_free, NULL); - /* drop the notifications timer source */ if (G_UNLIKELY (monitor->notifications_timer_id != 0)) g_source_remove (monitor->notifications_timer_id); @@ -257,7 +235,7 @@ thunar_vfs_monitor_finalize (GObject *object) thunar_vfs_path_unref (((ThunarVfsMonitorHandle *) lp->data)->path); _thunar_vfs_slice_free (ThunarVfsMonitorHandle, lp->data); } - g_list_free (monitor->handles); + g_slist_free (monitor->handles); /* release the monitor lock */ g_mutex_free (monitor->lock); @@ -347,7 +325,7 @@ thunar_vfs_monitor_notifications_timer (gpointer user_data) ThunarVfsMonitorHandle *handle; ThunarVfsMonitor *monitor = THUNAR_VFS_MONITOR (user_data); ThunarVfsPath *path; - GList *lp; + GSList *lp; /* take an additional reference on the monitor, * so we don't accidently * release the monitor while processing the notifications. @@ -530,32 +508,27 @@ static gboolean thunar_vfs_monitor_is_excluded_path (ThunarVfsMonitor *monitor, ThunarVfsPath *path) { - GList *iter; - gboolean excluded = FALSE; - gchar *path_string; - gint length; + gboolean excluded = FALSE; + gchar *path_string; - _thunar_vfs_return_val_if_fail (THUNAR_VFS_IS_MONITOR (monitor), TRUE); - _thunar_vfs_return_val_if_fail (path != NULL, TRUE); + _thunar_vfs_return_val_if_fail (THUNAR_VFS_IS_MONITOR (monitor), FALSE); + _thunar_vfs_return_val_if_fail (path != NULL, FALSE); +#ifdef HAVE_LINUX /* Turn path into a string */ path_string = thunar_vfs_path_dup_string (path); if (G_LIKELY (path_string != NULL)) { - length = strlen (path_string); - - /* Match path against all exclude patterns. Return TRUE if it matches at - * least one of these patterns */ - for (iter = g_list_first (monitor->excluded_paths); iter != NULL; iter = g_list_next (iter)) - if (g_pattern_match (iter->data, length, path_string, NULL)) - { - excluded = TRUE; - break; - } + /* check if the path is in /proc or /dev */ + if (strncmp (path_string, "/proc/", 6) == 0 + || strncmp (path_string, "/dev/", 5) == 0) + excluded = TRUE; + /* cleanup */ g_free (path_string); } +#endif return excluded; } @@ -611,7 +584,8 @@ thunar_vfs_monitor_add_directory (ThunarVfsMonitor *monitor, g_return_val_if_fail (callback != NULL, NULL); g_return_val_if_fail (path != NULL, NULL); - if (G_UNLIKELY (_thunar_vfs_path_is_local (path) && thunar_vfs_monitor_is_excluded_path (monitor, path))) + if (G_UNLIKELY (_thunar_vfs_path_is_local (path) + && thunar_vfs_monitor_is_excluded_path (monitor, path))) return NULL; /* acquire the monitor lock */ @@ -637,7 +611,7 @@ thunar_vfs_monitor_add_directory (ThunarVfsMonitor *monitor, #endif /* add the handle to the monitor */ - monitor->handles = g_list_prepend (monitor->handles, handle); + monitor->handles = g_slist_prepend (monitor->handles, handle); /* release the monitor lock */ g_mutex_unlock (monitor->lock); @@ -678,7 +652,8 @@ thunar_vfs_monitor_add_file (ThunarVfsMonitor *monitor, g_return_val_if_fail (callback != NULL, NULL); g_return_val_if_fail (path != NULL, NULL); - if (G_UNLIKELY (_thunar_vfs_path_is_local (path) && thunar_vfs_monitor_is_excluded_path (monitor, path))) + if (G_UNLIKELY (_thunar_vfs_path_is_local (path) + && thunar_vfs_monitor_is_excluded_path (monitor, path))) return NULL; /* acquire the monitor lock */ @@ -704,7 +679,7 @@ thunar_vfs_monitor_add_file (ThunarVfsMonitor *monitor, #endif /* add the handle to the monitor */ - monitor->handles = g_list_prepend (monitor->handles, handle); + monitor->handles = g_slist_prepend (monitor->handles, handle); /* release the monitor lock */ g_mutex_unlock (monitor->lock); @@ -726,7 +701,11 @@ thunar_vfs_monitor_remove (ThunarVfsMonitor *monitor, ThunarVfsMonitorHandle *handle) { g_return_if_fail (THUNAR_VFS_IS_MONITOR (monitor)); - g_return_if_fail (g_list_find (monitor->handles, handle) != NULL); + g_return_if_fail (handle == NULL || g_slist_find (monitor->handles, handle) != NULL); + + /* leave when the handle is null */ + if (G_UNLIKELY (handle == NULL)) + return; /* acquire the monitor lock */ g_mutex_lock (monitor->lock); @@ -747,7 +726,7 @@ thunar_vfs_monitor_remove (ThunarVfsMonitor *monitor, #endif /* unlink the handle */ - monitor->handles = g_list_remove (monitor->handles, handle); + monitor->handles = g_slist_remove (monitor->handles, handle); /* release the path */ thunar_vfs_path_unref (handle->path); @@ -777,7 +756,7 @@ thunar_vfs_monitor_feed (ThunarVfsMonitor *monitor, { ThunarVfsMonitorHandle *handle; ThunarVfsPath *parent; - GList *lp; + GSList *lp; g_return_if_fail (THUNAR_VFS_IS_MONITOR (monitor)); g_return_if_fail (event == THUNAR_VFS_MONITOR_EVENT_CHANGED