Avoid race condition on changes. Ensure timers restart even on exceptions.
This commit is contained in:
parent
f73aff54bb
commit
6e76fadd36
|
@ -35,6 +35,7 @@ namespace SparkleShare {
|
||||||
private FileSystemWatcher Watcher;
|
private FileSystemWatcher Watcher;
|
||||||
private bool HasChanged = false;
|
private bool HasChanged = false;
|
||||||
private DateTime LastChange;
|
private DateTime LastChange;
|
||||||
|
private System.Object ChangeLock = new System.Object();
|
||||||
|
|
||||||
public string Name;
|
public string Name;
|
||||||
public string Domain;
|
public string Domain;
|
||||||
|
@ -126,6 +127,7 @@ namespace SparkleShare {
|
||||||
BufferTimer.Elapsed += delegate (object o, ElapsedEventArgs args) {
|
BufferTimer.Elapsed += delegate (object o, ElapsedEventArgs args) {
|
||||||
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Checking for changes.");
|
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Checking for changes.");
|
||||||
|
|
||||||
|
lock(ChangeLock) {
|
||||||
if (HasChanged) {
|
if (HasChanged) {
|
||||||
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Changes found, checking if settled.");
|
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Changes found, checking if settled.");
|
||||||
DateTime now = DateTime.UtcNow;
|
DateTime now = DateTime.UtcNow;
|
||||||
|
@ -136,6 +138,7 @@ namespace SparkleShare {
|
||||||
AddCommitAndPush ();
|
AddCommitAndPush ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BufferTimer.Start ();
|
BufferTimer.Start ();
|
||||||
|
@ -156,15 +159,18 @@ namespace SparkleShare {
|
||||||
if (!ShouldIgnore (args.Name)) {
|
if (!ShouldIgnore (args.Name)) {
|
||||||
SparkleHelpers.DebugInfo ("Event", "[" + Name + "] " + wct.ToString () + " '" + args.Name + "'");
|
SparkleHelpers.DebugInfo ("Event", "[" + Name + "] " + wct.ToString () + " '" + args.Name + "'");
|
||||||
FetchTimer.Stop ();
|
FetchTimer.Stop ();
|
||||||
|
lock(ChangeLock) {
|
||||||
LastChange = DateTime.UtcNow;
|
LastChange = DateTime.UtcNow;
|
||||||
HasChanged = true;
|
HasChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// When there are changes we generally want to Add, Commit and Push
|
// When there are changes we generally want to Add, Commit and Push
|
||||||
// so this method does them all with appropriate timers, etc switched off
|
// so this method does them all with appropriate timers, etc switched off
|
||||||
public void AddCommitAndPush ()
|
public void AddCommitAndPush ()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
BufferTimer.Stop ();
|
BufferTimer.Stop ();
|
||||||
FetchTimer.Stop ();
|
FetchTimer.Stop ();
|
||||||
|
|
||||||
|
@ -174,13 +180,13 @@ namespace SparkleShare {
|
||||||
Commit (Message);
|
Commit (Message);
|
||||||
Fetch ();
|
Fetch ();
|
||||||
Push ();
|
Push ();
|
||||||
|
SparkleHelpers.CheckForUnicorns (Message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
FetchTimer.Start ();
|
FetchTimer.Start ();
|
||||||
BufferTimer.Start ();
|
BufferTimer.Start ();
|
||||||
|
}
|
||||||
SparkleHelpers.CheckForUnicorns (Message);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stages the made changes
|
// Stages the made changes
|
||||||
|
@ -207,6 +213,7 @@ namespace SparkleShare {
|
||||||
// Fetches changes from the remote repo
|
// Fetches changes from the remote repo
|
||||||
public void Fetch ()
|
public void Fetch ()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
FetchTimer.Stop ();
|
FetchTimer.Stop ();
|
||||||
// SparkleUI.NotificationIcon.SetSyncingState ();
|
// SparkleUI.NotificationIcon.SetSyncingState ();
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
|
||||||
|
@ -218,8 +225,11 @@ namespace SparkleShare {
|
||||||
if (!Output.Contains ("up to date"))
|
if (!Output.Contains ("up to date"))
|
||||||
Rebase ();
|
Rebase ();
|
||||||
// SparkleUI.NotificationIcon.SetIdleState ();
|
// SparkleUI.NotificationIcon.SetIdleState ();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
FetchTimer.Start ();
|
FetchTimer.Start ();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Merges the fetched changes
|
// Merges the fetched changes
|
||||||
public void Rebase ()
|
public void Rebase ()
|
||||||
|
|
Loading…
Reference in a new issue