mac watcher: fix race condition where the same repo may be triggered multiple times. closes #1083

This commit is contained in:
Hylke Bons 2012-11-29 18:51:40 +00:00
parent aea3176846
commit 7a7f591cd6

View file

@ -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