fetcher git: Catch stream errors when process has been killed by user. Fixes #1187

This commit is contained in:
Hylke Bons 2013-06-20 21:01:03 +01:00
parent 064fe7f00d
commit 711811f13d
2 changed files with 50 additions and 39 deletions

View file

@ -128,6 +128,7 @@ namespace SparkleLib.Git {
DateTime last_change = DateTime.Now; DateTime last_change = DateTime.Now;
TimeSpan change_interval = new TimeSpan (0, 0, 0, 1); TimeSpan change_interval = new TimeSpan (0, 0, 0, 1);
try {
while (!this.git.StandardError.EndOfStream) { while (!this.git.StandardError.EndOfStream) {
string line = this.git.StandardError.ReadLine (); string line = this.git.StandardError.ReadLine ();
Match match = progress_regex.Match (line); Match match = progress_regex.Match (line);
@ -171,6 +172,11 @@ namespace SparkleLib.Git {
} }
} }
} catch (Exception e) {
IsActive = false;
return false;
}
this.git.WaitForExit (); this.git.WaitForExit ();
if (this.git.ExitCode == 0) { if (this.git.ExitCode == 0) {
@ -277,8 +283,7 @@ namespace SparkleLib.Git {
public override void Stop () public override void Stop ()
{ {
try { try {
if (this.git != null) { if (this.git != null && !this.git.HasExited) {
this.git.Close ();
this.git.Kill (); this.git.Kill ();
this.git.Dispose (); this.git.Dispose ();
} }

View file

@ -56,7 +56,7 @@ namespace SparkleLib {
public string RequiredFingerprint { get; protected set; } public string RequiredFingerprint { get; protected set; }
public readonly bool FetchPriorHistory = false; public readonly bool FetchPriorHistory = false;
public string TargetFolder { get; protected set; } public string TargetFolder { get; protected set; }
public bool IsActive { get; private set; } public bool IsActive { get; protected set; }
public string Identifier; public string Identifier;
public SparkleFetcherInfo OriginalFetcherInfo; public SparkleFetcherInfo OriginalFetcherInfo;
@ -150,10 +150,16 @@ namespace SparkleLib {
} else { } else {
Thread.Sleep (500); Thread.Sleep (500);
if (IsActive) {
SparkleLogger.LogInfo ("Fetcher", "Failed"); SparkleLogger.LogInfo ("Fetcher", "Failed");
Failed ();
} else {
SparkleLogger.LogInfo ("Fetcher", "Failed: cancelled by user");
}
IsActive = false; IsActive = false;
Failed ();
} }
}); });