From: pgkos Date: Fri, 27 Jan 2017 15:41:34 +0100 Subject: [PATCH 1/1] Fix race in thunar_file_rename and thunar_folder_monitor --- thunar/thunar-file.c | 6 +++++- thunar/thunar-file.h | 2 ++ thunar/thunar-folder.c | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index c8ca881d..c6d11e09 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 (file_rename_mutex); @@ -1928,6 +1929,8 @@ 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 +1947,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-file.h b/thunar/thunar-file.h index cfc3d050..aefa825a 100644 --- a/thunar/thunar-file.h +++ b/thunar/thunar-file.h @@ -31,6 +31,8 @@ G_BEGIN_DECLS; +G_LOCK_EXTERN(file_rename_mutex); + typedef struct _ThunarFileClass ThunarFileClass; typedef struct _ThunarFile ThunarFile; diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c index 9decb899..add021bb 100644 --- a/thunar/thunar-folder.c +++ b/thunar/thunar-folder.c @@ -724,6 +724,8 @@ thunar_folder_monitor (GFileMonitor *monitor, _thunar_return_if_fail (THUNAR_IS_FILE (folder->corresponding_file)); _thunar_return_if_fail (G_IS_FILE (event_file)); + G_LOCK (file_rename_mutex); + /* check on which file the event occurred */ if (!g_file_equal (event_file, thunar_file_get_file (folder->corresponding_file))) { @@ -828,6 +830,8 @@ thunar_folder_monitor (GFileMonitor *monitor, thunar_file_reload (folder->corresponding_file); } } + + G_UNLOCK (file_rename_mutex); } -- 2.11.0