From 7a7f591cd63d0b9dac169611f09025f93938f764 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 29 Nov 2012 18:51:40 +0000 Subject: [PATCH] mac watcher: fix race condition where the same repo may be triggered multiple times. closes #1083 --- SparkleShare/Mac/SparkleController.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/SparkleShare/Mac/SparkleController.cs b/SparkleShare/Mac/SparkleController.cs index 7e55d06e..2ff9eed6 100755 --- a/SparkleShare/Mac/SparkleController.cs +++ b/SparkleShare/Mac/SparkleController.cs @@ -49,7 +49,7 @@ namespace SparkleShare { SparkleLib.Git.SparkleGit.ExecPath = Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core"); } - + public override void Initialize () { base.Initialize (); @@ -60,15 +60,28 @@ namespace SparkleShare { FileSystemEventArgs fse_args = new FileSystemEventArgs (WatcherChangeTypes.Changed, Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, path), Path.GetFileName (path)); + FileActivityTask [] tasks = new FileActivityTask [Repositories.Length]; + // FIXME: There are cases where the wrong repo is triggered, so // we trigger all of them for now. Causes only slightly more overhead - foreach (SparkleRepoBase repo in Repositories) - new Thread (() => { repo.OnFileActivity (fse_args); }).Start (); + int i = 0; + foreach (SparkleRepoBase repo in Repositories) { + tasks [i] = MacActivityTask (repo, fse_args); + tasks [i] (); + i++; + } }; } + private delegate void FileActivityTask (); + + private FileActivityTask MacActivityTask (SparkleRepoBase repo, FileSystemEventArgs fse_args) { + return delegate { new Thread (() => { repo.OnFileActivity (fse_args); }).Start (); }; + } + + public override void CreateStartupItem () { // There aren't any bindings in MonoMac to support this yet, so