From 4f3c9b975794947245bf48ce34b91762379c382e Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 29 Mar 2012 17:05:18 +0100 Subject: [PATCH] controller: fix some crashes due to simultaneous thread access on repo list --- SparkleShare/SparkleControllerBase.cs | 21 ++++++++++++++++----- SparkleShare/SparkleSetupController.cs | 12 ++++++------ SparkleShare/SparkleStatusIconController.cs | 11 ++--------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 24306c04..534ca4f6 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -32,7 +32,18 @@ namespace SparkleShare { public abstract class SparkleControllerBase { - public List Repositories = new List (); + public SparkleRepoBase [] Repositories { + get { + lock (this.repo_lock) { + SparkleRepoBase [] repositories = + this.repositories.GetRange (0, this.repositories.Count).ToArray (); + + return repositories; + } + } + } + + public List repositories = new List (); public readonly string SparklePath = SparkleConfig.DefaultConfig.FoldersPath; public double ProgressPercentage = 0.0; @@ -632,7 +643,7 @@ namespace SparkleShare { lock (this.repo_lock) { - Repositories.Add (repo); + this.repositories.Add (repo); } repo.Initialize (); @@ -646,12 +657,12 @@ namespace SparkleShare { string folder_name = Path.GetFileName (folder_path); lock (this.repo_lock) { - for (int i = 0; i < Repositories.Count; i++) { - SparkleRepoBase repo = Repositories [i]; + for (int i = 0; i < this.repositories.Count; i++) { + SparkleRepoBase repo = this.repositories [i]; if (repo.Name.Equals (folder_name)) { repo.Dispose (); - Repositories.Remove (repo); + this.repositories.Remove (repo); repo = null; break; } diff --git a/SparkleShare/SparkleSetupController.cs b/SparkleShare/SparkleSetupController.cs index aa16a703..20ce6af6 100755 --- a/SparkleShare/SparkleSetupController.cs +++ b/SparkleShare/SparkleSetupController.cs @@ -241,12 +241,6 @@ namespace SparkleShare { } - public void StartupItemChanged (bool create_startup_item) - { - this.create_startup_item = create_startup_item; - } - - public void HistoryItemChanged (bool fetch_prior_history) { this.fetch_prior_history = fetch_prior_history; @@ -305,6 +299,12 @@ namespace SparkleShare { } + public void StartupItemChanged (bool create_startup_item) + { + this.create_startup_item = create_startup_item; + } + + public void CheckAddPage (string address, string remote_path, int selected_plugin) { address = address.Trim (); diff --git a/SparkleShare/SparkleStatusIconController.cs b/SparkleShare/SparkleStatusIconController.cs index f24cd2ea..9f726d99 100755 --- a/SparkleShare/SparkleStatusIconController.cs +++ b/SparkleShare/SparkleStatusIconController.cs @@ -81,12 +81,8 @@ namespace SparkleShare { get { double size = 0; - foreach (SparkleRepoBase repo in - Program.Controller.Repositories.GetRange ( - 0, Program.Controller.Repositories.Count)) { - + foreach (SparkleRepoBase repo in Program.Controller.Repositories) size += repo.Size + repo.HistorySize; - } if (size == 0) return ""; @@ -167,10 +163,7 @@ namespace SparkleShare { int repos_syncing_up = 0; int repos_syncing_down = 0; - foreach (SparkleRepoBase repo in - Program.Controller.Repositories.GetRange ( - 0, Program.Controller.Repositories.Count)) { - + foreach (SparkleRepoBase repo in Program.Controller.Repositories) { if (repo.Status == SyncStatus.SyncUp) repos_syncing_up++;