From ec0e96376864611b7cce6b15e5bddd86576277cf Mon Sep 17 00:00:00 2001 From: therzok Date: Thu, 20 Jun 2019 16:43:42 +0300 Subject: Move existence checks for when a file is deleted onto the background thread --- .../MonoDevelop.Projects/Project.cs | 33 +++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs') diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs index 45139f8c57..e53cda474c 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs @@ -4516,9 +4516,12 @@ namespace MonoDevelop.Projects LoggingService.LogError ("OnFileRenamed error.", ex); } + bool exists = File.Exists (sourceFile) || Directory.Exists (sourceFile); + Runtime.RunInMainThread (() => { OnFileCreatedExternally (targetFile); - OnFileDeletedExternally (sourceFile); + if (!exists) + OnFileDeletedExternally (sourceFile); }); } @@ -4559,14 +4562,34 @@ namespace MonoDevelop.Projects } } + static readonly ObjectPool> filePathListPool = ObjectPool.Create (new PooledListPolicy ()); + void OnFileDeleted (object sender, FileEventArgs e) { if (Runtime.IsMainThread) return; + List paths = null; + foreach (var file in e) { + var path = file.FileName; + bool exists = File.Exists (path) || Directory.Exists (path); + + if (!exists) { + paths ??= filePathListPool.Get (); + paths.Add (path); + } + } + + if (paths == null) + return; + Runtime.RunInMainThread (() => { - foreach (FileEventInfo info in e) { - OnFileDeletedExternally (info.FileName); + try { + foreach (var path in paths) { + OnFileDeletedExternally (path); + } + } finally { + filePathListPool.Return (paths); } }); } @@ -4681,10 +4704,6 @@ namespace MonoDevelop.Projects // the file being saved. Saving with TextFileUtility will result in // FileService.SystemRename being called to move a temporary file // to the file being saved which deletes and then creates the file. - bool notDeleted = File.Exists (fileName) || Directory.Exists (fileName); - if (notDeleted) - return; - Files.Remove (fileName); } -- cgit v1.2.3