From 02e6567fdcf1f61f78c558f7028c097a1cfbbee8 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 30 May 2013 13:05:33 +0100 Subject: [PATCH] repo: Fix race condition causing the statusicon to report an error where there isn't one --- SparkleLib/SparkleRepoBase.cs | 37 ++++++++++++++++++--------- SparkleShare/SparkleControllerBase.cs | 15 ++++++----- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index 4f357940..f934a0a6 100755 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -158,8 +158,6 @@ namespace SparkleLib { string identifier_file_path = Path.Combine (LocalPath, ".sparkleshare"); File.SetAttributes (identifier_file_path, FileAttributes.Hidden); - SyncStatusChanged += delegate (SyncStatus status) { Status = status; }; - if (!UseCustomWatcher) this.watcher = new SparkleWatcher (LocalPath); @@ -277,7 +275,8 @@ namespace SparkleLib { } while (HasLocalChanges); } else { - SyncStatusChanged (SyncStatus.Idle); + Status = SyncStatus.Idle; + SyncStatusChanged (Status); } } else { @@ -334,7 +333,8 @@ namespace SparkleLib { SparkleLogger.LogInfo ("SyncUp", Name + " | Initiated"); HasUnsyncedChanges = true; - SyncStatusChanged (SyncStatus.SyncUp); + Status = SyncStatus.SyncUp; + SyncStatusChanged (Status); if (SyncUp ()) { SparkleLogger.LogInfo ("SyncUp", Name + " | Done"); @@ -343,9 +343,11 @@ namespace SparkleLib { HasUnsyncedChanges = false; this.poll_interval = PollInterval.Long; - SyncStatusChanged (SyncStatus.Idle); this.listener.Announce (new SparkleAnnouncement (Identifier, CurrentRevision)); + Status = SyncStatus.Idle; + SyncStatusChanged (Status); + } else { SparkleLogger.LogInfo ("SyncUp", Name + " | Error"); SyncDownBase (); @@ -357,11 +359,15 @@ namespace SparkleLib { HasUnsyncedChanges = false; this.listener.Announce (new SparkleAnnouncement (Identifier, CurrentRevision)); - SyncStatusChanged (SyncStatus.Idle); + + Status = SyncStatus.Idle; + SyncStatusChanged (Status); } else { this.poll_interval = PollInterval.Short; - SyncStatusChanged (SyncStatus.Error); + + Status = SyncStatus.Error; + SyncStatusChanged (Status); } } @@ -380,7 +386,9 @@ namespace SparkleLib { SparkleLogger.LogInfo ("SyncDown", Name + " | Initiated"); - SyncStatusChanged (SyncStatus.SyncDown); + Status = SyncStatus.SyncDown; + SyncStatusChanged (Status); + string pre_sync_revision = CurrentRevision; if (SyncDown ()) { @@ -413,25 +421,30 @@ namespace SparkleLib { // conflict. Tries only once, then lets // the timer try again periodically if (HasUnsyncedChanges) { - SyncStatusChanged (SyncStatus.SyncUp); + Status = SyncStatus.SyncUp; + SyncStatusChanged (Status); if (SyncUp ()) HasUnsyncedChanges = false; } - SyncStatusChanged (SyncStatus.Idle); + Status = SyncStatus.Idle; + SyncStatusChanged (Status); } else { SparkleLogger.LogInfo ("SyncDown", Name + " | Error"); ChangeSets = GetChangeSets (); - SyncStatusChanged (SyncStatus.Error); + + Status = SyncStatus.Error; + SyncStatusChanged (Status); } ProgressPercentage = 0.0; ProgressSpeed = 0.0; - SyncStatusChanged (SyncStatus.Idle); + Status = SyncStatus.Idle; + SyncStatusChanged (Status); if (!UseCustomWatcher) this.watcher.Enable (); diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index f6d881d5..309a6712 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -496,18 +496,21 @@ namespace SparkleShare { private void UpdateState () { bool has_unsynced_repos = false; - + bool has_syncing_repos = false; + foreach (SparkleRepoBase repo in Repositories) { if (repo.Status == SyncStatus.SyncDown || repo.Status == SyncStatus.SyncUp || repo.IsBuffering) { - OnSyncing (); - return; + has_syncing_repos = true; + break; - } else if (repo.HasUnsyncedChanges) { + } else if (repo.Status == SyncStatus.Idle && repo.HasUnsyncedChanges) { has_unsynced_repos = true; } } - - if (has_unsynced_repos) + + if (has_syncing_repos) + OnSyncing (); + else if (has_unsynced_repos) OnError (); else OnIdle ();