From f9e054872c7ddc065cd4008bb9e8ce1d364aeeed Mon Sep 17 00:00:00 2001 From: pgkos Date: Tue, 31 Jan 2017 19:30:55 +0100 Subject: Fix crash and hang while renaming --- thunar/thunar-file.c | 13 +++++++++++-- thunar/thunar-folder.c | 7 +++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index c8ca881d..ccca2c9d 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -121,6 +121,7 @@ static gboolean thunar_file_same_filesystem (const ThunarFile G_LOCK_DEFINE_STATIC (file_cache_mutex); G_LOCK_DEFINE_STATIC (file_content_type_mutex); +G_LOCK_DEFINE_STATIC (file_rename_mutex); @@ -780,7 +781,9 @@ thunar_file_monitor (GFileMonitor *monitor, /* the event occurred for the monitored ThunarFile */ if (event_type == G_FILE_MONITOR_EVENT_MOVED) { + G_LOCK (file_rename_mutex); thunar_file_monitor_moved (file, other_path); + G_UNLOCK (file_rename_mutex); return; } @@ -797,6 +800,9 @@ thunar_file_monitor (GFileMonitor *monitor, /* reload the target file if cached */ if (other_path == NULL) return; + + G_LOCK (file_rename_mutex); + other_file = thunar_file_cache_lookup (other_path); if (other_file) thunar_file_reload (other_file); @@ -813,13 +819,14 @@ thunar_file_monitor (GFileMonitor *monitor, thunar_file_reload_parent (other_file); g_object_unref (other_file); + + G_UNLOCK (file_rename_mutex); } return; } } - static void thunar_file_watch_destroyed (gpointer data) { @@ -1928,6 +1935,7 @@ thunar_file_rename (ThunarFile *file, } else { + G_LOCK (file_rename_mutex); /* try to rename the file */ renamed_file = g_file_set_display_name (file->gfile, name, cancellable, error); @@ -1944,11 +1952,12 @@ thunar_file_rename (ThunarFile *file, /* emit the file changed signal */ thunar_file_changed (file); } - + G_UNLOCK (file_rename_mutex); return TRUE; } else { + G_UNLOCK (file_rename_mutex); return FALSE; } } diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index 9decb899..a90988e4 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -276,6 +276,9 @@ thunar_folder_finalize (GObject *object) { ThunarFolder *folder = THUNAR_FOLDER (object); + if (folder->corresponding_file) + thunar_file_unwatch (folder->corresponding_file); + /* disconnect from the ThunarFileMonitor instance */ g_signal_handlers_disconnect_matched (folder->file_monitor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, folder); g_object_unref (folder->file_monitor); @@ -356,7 +359,11 @@ thunar_folder_set_property (GObject *object, switch (prop_id) { case PROP_CORRESPONDING_FILE: + if (folder->corresponding_file) + thunar_file_unwatch (folder->corresponding_file); folder->corresponding_file = g_value_dup_object (value); + if (folder->corresponding_file) + thunar_file_watch (folder->corresponding_file); break; case PROP_LOADING: -- 2.11.0