fetcher git: Catch stream errors when process has been killed by user. Fixes #1187
This commit is contained in:
parent
064fe7f00d
commit
711811f13d
|
@ -128,49 +128,55 @@ 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);
|
||||||
|
|
||||||
while (!this.git.StandardError.EndOfStream) {
|
try {
|
||||||
string line = this.git.StandardError.ReadLine ();
|
while (!this.git.StandardError.EndOfStream) {
|
||||||
Match match = progress_regex.Match (line);
|
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"));
|
|
||||||
|
|
||||||
// The cloning progress consists of two stages: the "Compressing
|
double number = 0.0;
|
||||||
// objects" stage which we count as 20% of the total progress, and
|
if (match.Success) {
|
||||||
// the "Receiving objects" stage which we count as the last 80%
|
number = double.Parse (match.Groups [1].Value, new CultureInfo ("en-US"));
|
||||||
if (line.Contains ("|"))
|
|
||||||
number = (number / 100 * 80 + 20); // "Receiving objects" stage
|
// The cloning progress consists of two stages: the "Compressing
|
||||||
else
|
// objects" stage which we count as 20% of the total progress, and
|
||||||
number = (number / 100 * 20); // "Compressing objects" stage
|
// 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 {
|
} else {
|
||||||
SparkleLogger.LogInfo ("Fetcher", line);
|
SparkleLogger.LogInfo ("Fetcher", line);
|
||||||
line = line.Trim (new char [] {' ', '@'});
|
line = line.Trim (new char [] {' ', '@'});
|
||||||
|
|
||||||
if (line.StartsWith ("fatal:", StringComparison.InvariantCultureIgnoreCase) ||
|
if (line.StartsWith ("fatal:", StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
line.StartsWith ("error:", 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!")) {
|
} else if (line.StartsWith ("WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!")) {
|
||||||
base.errors.Add ("warning: Remote host identification has changed!");
|
base.errors.Add ("warning: Remote host identification has changed!");
|
||||||
|
|
||||||
} else if (line.StartsWith ("WARNING: POSSIBLE DNS SPOOFING DETECTED!")) {
|
} else if (line.StartsWith ("WARNING: POSSIBLE DNS SPOOFING DETECTED!")) {
|
||||||
base.errors.Add ("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 ();
|
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 ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
SparkleLogger.LogInfo ("Fetcher", "Failed");
|
|
||||||
|
if (IsActive) {
|
||||||
|
SparkleLogger.LogInfo ("Fetcher", "Failed");
|
||||||
|
Failed ();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SparkleLogger.LogInfo ("Fetcher", "Failed: cancelled by user");
|
||||||
|
}
|
||||||
|
|
||||||
IsActive = false;
|
IsActive = false;
|
||||||
Failed ();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue