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,49 +128,55 @@ namespace SparkleLib.Git {
DateTime last_change = DateTime.Now;
TimeSpan change_interval = new TimeSpan (0, 0, 0, 1);
while (!this.git.StandardError.EndOfStream) {
string line = this.git.StandardError.ReadLine ();
Match match = progress_regex.Match (line);
double number = 0.0;
if (match.Success) {
number = double.Parse (match.Groups [1].Value, new CultureInfo ("en-US"));
try {
while (!this.git.StandardError.EndOfStream) {
string line = this.git.StandardError.ReadLine ();
Match match = progress_regex.Match (line);
// The cloning progress consists of two stages: the "Compressing
// objects" stage which we count as 20% of the total progress, and
// the "Receiving objects" stage which we count as the last 80%
if (line.Contains ("|"))
number = (number / 100 * 80 + 20); // "Receiving objects" stage
else
number = (number / 100 * 20); // "Compressing objects" stage
double number = 0.0;
if (match.Success) {
number = double.Parse (match.Groups [1].Value, new CultureInfo ("en-US"));
// The cloning progress consists of two stages: the "Compressing
// objects" stage which we count as 20% of the total progress, and
// the "Receiving objects" stage which we count as the last 80%
if (line.Contains ("|"))
number = (number / 100 * 80 + 20); // "Receiving objects" stage
else
number = (number / 100 * 20); // "Compressing objects" stage
} else {
SparkleLogger.LogInfo ("Fetcher", line);
line = line.Trim (new char [] {' ', '@'});
} else {
SparkleLogger.LogInfo ("Fetcher", line);
line = line.Trim (new char [] {' ', '@'});
if (line.StartsWith ("fatal:", StringComparison.InvariantCultureIgnoreCase) ||
line.StartsWith ("error:", StringComparison.InvariantCultureIgnoreCase)) {
if (line.StartsWith ("fatal:", StringComparison.InvariantCultureIgnoreCase) ||
line.StartsWith ("error:", StringComparison.InvariantCultureIgnoreCase)) {
base.errors.Add (line);
base.errors.Add (line);
} else if (line.StartsWith ("WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!")) {
base.errors.Add ("warning: Remote host identification has changed!");
} else if (line.StartsWith ("WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!")) {
base.errors.Add ("warning: Remote host identification has changed!");
} else if (line.StartsWith ("WARNING: POSSIBLE DNS SPOOFING DETECTED!")) {
base.errors.Add ("warning: Possible DNS spoofing detected!");
} else if (line.StartsWith ("WARNING: POSSIBLE DNS SPOOFING DETECTED!")) {
base.errors.Add ("warning: Possible DNS spoofing detected!");
}
}
if (number >= percentage) {
percentage = number;
if (DateTime.Compare (last_change, DateTime.Now.Subtract (change_interval)) < 0) {
base.OnProgressChanged (percentage);
last_change = DateTime.Now;
}
}
}
if (number >= percentage) {
percentage = number;
if (DateTime.Compare (last_change, DateTime.Now.Subtract (change_interval)) < 0) {
base.OnProgressChanged (percentage);
last_change = DateTime.Now;
}
}
}
} catch (Exception e) {
IsActive = false;
return false;
}
this.git.WaitForExit ();
if (this.git.ExitCode == 0) {
@ -277,8 +283,7 @@ namespace SparkleLib.Git {
public override void Stop ()
{
try {
if (this.git != null) {
this.git.Close ();
if (this.git != null && !this.git.HasExited) {
this.git.Kill ();
this.git.Dispose ();
}

View file

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