fetcher: log exceptions more cleanly

This commit is contained in:
Hylke Bons 2012-11-22 12:31:48 +00:00
parent 3b51e0b315
commit 0c3905e58a
6 changed files with 26 additions and 32 deletions

View file

@ -294,7 +294,7 @@ namespace SparkleLib.Git {
} }
} catch (Exception e) { } catch (Exception e) {
SparkleLogger.LogInfo ("Fetcher", "Failed to dispose properly: " + e.Message); SparkleLogger.LogInfo ("Fetcher", "Failed to dispose properly", e);
} }
} }

View file

@ -411,8 +411,6 @@ namespace SparkleLib.Git {
{ {
SparkleGit git = new SparkleGit (LocalPath, "add --all"); SparkleGit git = new SparkleGit (LocalPath, "add --all");
git.StartAndWaitForExit (); git.StartAndWaitForExit ();
SparkleLogger.LogInfo ("Git", Name + " | Changes staged");
} }
@ -533,9 +531,7 @@ namespace SparkleLib.Git {
SparkleLogger.LogInfo ("Git", Name + " | Conflict type: " + line); SparkleLogger.LogInfo ("Git", Name + " | Conflict type: " + line);
// Ignore conflicts in the .sparkleshare file and use the local version // Ignore conflicts in the .sparkleshare file and use the local version
if (conflicting_path.EndsWith (".sparkleshare") || if (conflicting_path.EndsWith (".sparkleshare") || conflicting_path.EndsWith (".empty")) {
conflicting_path.EndsWith (".empty")) {
// Recover local version // Recover local version
SparkleGit git_theirs = new SparkleGit (LocalPath, "checkout --theirs \"" + conflicting_path + "\""); SparkleGit git_theirs = new SparkleGit (LocalPath, "checkout --theirs \"" + conflicting_path + "\"");
git_theirs.StartAndWaitForExit (); git_theirs.StartAndWaitForExit ();
@ -574,12 +570,8 @@ namespace SparkleLib.Git {
// The local version has been modified, but the server version was removed // The local version has been modified, but the server version was removed
} else if (line.StartsWith ("DU")) { } else if (line.StartsWith ("DU")) {
// The modified local version is already in the checkout, so it just needs to be added.
// The modified local version is already in the // We need to specifically mention the file, so we can't reuse the Add () method
// checkout, so it just needs to be added.
//
// We need to specifically mention the file, so
// we can't reuse the Add () method
SparkleGit git_add = new SparkleGit (LocalPath, "add \"" + conflicting_path + "\""); SparkleGit git_add = new SparkleGit (LocalPath, "add \"" + conflicting_path + "\"");
git_add.StartAndWaitForExit (); git_add.StartAndWaitForExit ();

View file

@ -68,7 +68,7 @@ namespace SparkleLib {
else if (byte_count >= 1024) else if (byte_count >= 1024)
return String.Format ("{0:##.##} ᴋʙ", Math.Round (byte_count / 1024, 0)); return String.Format ("{0:##.##} ᴋʙ", Math.Round (byte_count / 1024, 0));
else else
return byte_count.ToString () + " bytes"; return byte_count.ToString () + " ʙ";
} }
} }
} }

View file

@ -162,8 +162,8 @@ namespace SparkleLib {
IsActive = false; IsActive = false;
bool repo_is_encrypted = bool repo_is_encrypted = (RemoteUrl.AbsolutePath.Contains ("-crypto") ||
(RemoteUrl.AbsolutePath.Contains ("-crypto") || RemoteUrl.Host.Equals ("sparkleshare.net")); RemoteUrl.Host.Equals ("sparkleshare.net"));
Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings); Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
@ -257,29 +257,22 @@ namespace SparkleLib {
private string FetchHostKey () private string FetchHostKey ()
{ {
string host = RemoteUrl.Host; SparkleLogger.LogInfo ("Auth", "Fetching host key for " + RemoteUrl.Host);
int port = RemoteUrl.Port;
if (port < 1)
port = 22;
SparkleLogger.LogInfo ("Auth", "Fetching host key for " + host);
Process process = new Process () {
EnableRaisingEvents = true
};
Process process = new Process ();
process.StartInfo.FileName = "ssh-keyscan"; process.StartInfo.FileName = "ssh-keyscan";
process.StartInfo.Arguments = "-t rsa -p " + port + " " + host;
process.StartInfo.WorkingDirectory = SparkleConfig.DefaultConfig.TmpPath; process.StartInfo.WorkingDirectory = SparkleConfig.DefaultConfig.TmpPath;
process.StartInfo.UseShellExecute = false; process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true; process.StartInfo.CreateNoWindow = true;
process.EnableRaisingEvents = true;
if (RemoteUrl.Port < 1)
process.StartInfo.Arguments = "-t rsa -p 22 " + RemoteUrl.Host;
else
process.StartInfo.Arguments = "-t rsa -p " + RemoteUrl.Port + " " + RemoteUrl.Host;
process.Start (); process.Start ();
// Reading the standard output HAS to go before
// WaitForExit, or it will hang forever on output > 4096 bytes
string host_key = process.StandardOutput.ReadToEnd ().Trim (); string host_key = process.StandardOutput.ReadToEnd ().Trim ();
process.WaitForExit (); process.WaitForExit ();
@ -302,7 +295,7 @@ namespace SparkleLib {
return fingerprint.ToLower ().Replace ("-", ":"); return fingerprint.ToLower ().Replace ("-", ":");
} catch (Exception e) { } catch (Exception e) {
SparkleLogger.LogInfo ("Fetcher", "Failed creating fingerprint: " + e.Message + e.StackTrace); SparkleLogger.LogInfo ("Fetcher", "Failed creating fingerprint: " + e.Message + " " + e.StackTrace);
return null; return null;
} }
} }

View file

@ -26,10 +26,19 @@ namespace SparkleLib {
private static int log_size = 0; private static int log_size = 0;
public static void LogInfo (string type, string message) public static void LogInfo (string type, string message)
{
LogInfo (type, message, null);
}
public static void LogInfo (string type, string message, Exception exception)
{ {
string timestamp = DateTime.Now.ToString ("HH:mm:ss"); string timestamp = DateTime.Now.ToString ("HH:mm:ss");
string line = timestamp + " | " + type + " | " + message; string line = timestamp + " | " + type + " | " + message;
if (exception != null)
line += ": " + exception.Message + " " + exception.StackTrace;
if (SparkleConfig.DebugMode) if (SparkleConfig.DebugMode)
Console.WriteLine (line); Console.WriteLine (line);

View file

@ -77,7 +77,7 @@ namespace SparkleShare {
private void HideDockIcon () private void HideDockIcon ()
{ {
// Currently not supported, here for completeness sake (see Apple's docs) // Currently not supported by Apple's API
// NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.None; // NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.None;
} }