From 09df631e5b05019444df9184a4a3fa1c084364b3 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 5 Mar 2011 16:52:13 +0000 Subject: [PATCH] Fix ssh config file not being removed if needed --- SparkleShare/SparkleController.cs | 26 ++++++++++++++++---------- SparkleShare/SparkleShare.cs | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index 5164c64b..1a7cda69 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -917,13 +917,16 @@ namespace SparkleShare { private void DisableHostKeyCheckingForHost (string host) { - string ssh_config_file_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".ssh", "config"); - string ssh_config = "Host " + host + "\n\tStrictHostKeyChecking no"; + string ssh_config_file_path = SparkleHelpers.CombineMore ( + SparklePaths.HomePath, ".ssh", "config"); + + string ssh_config = Environment.NewLine + "Host " + host + + Environment.NewLine + "\tStrictHostKeyChecking no"; if (File.Exists (ssh_config_file_path)) { TextWriter writer = File.AppendText (ssh_config_file_path); - writer.WriteLine ("\n" + ssh_config); + writer.WriteLine (ssh_config); writer.Close (); } else { @@ -940,11 +943,11 @@ namespace SparkleShare { private void EnableHostKeyCheckingForHost (string host) { - string ssh_config_file_path = SparkleHelpers.CombineMore - (SparklePaths.HomePath, ".ssh", "config"); + string ssh_config_file_path = SparkleHelpers.CombineMore ( + SparklePaths.HomePath, ".ssh", "config"); - string ssh_config = "Host " + host + "\n" + - "\tStrictHostKeyChecking no"; + string ssh_config = Environment.NewLine + "Host " + host + + Environment.NewLine + "\tStrictHostKeyChecking no"; if (File.Exists (ssh_config_file_path)) { @@ -952,10 +955,11 @@ namespace SparkleShare { string current_ssh_config = reader.ReadToEnd (); reader.Close (); - current_ssh_config = current_ssh_config.Remove (current_ssh_config.IndexOf (ssh_config), - ssh_config.Length); + current_ssh_config = current_ssh_config.Remove ( + current_ssh_config.IndexOf (ssh_config), ssh_config.Length); - if (current_ssh_config.Trim ().Equals ("")) { + bool has_some_config = new Regex (@"[a-z]").IsMatch (current_ssh_config); + if (!has_some_config) { File.Delete (ssh_config_file_path); @@ -965,6 +969,8 @@ namespace SparkleShare { writer.WriteLine (current_ssh_config); writer.Close (); + //Syscall.chmod (ssh_config_file_path, FilePermissions.S_IRWXU); + } } diff --git a/SparkleShare/SparkleShare.cs b/SparkleShare/SparkleShare.cs index f8ae303a..b986ce44 100644 --- a/SparkleShare/SparkleShare.cs +++ b/SparkleShare/SparkleShare.cs @@ -109,7 +109,7 @@ namespace SparkleShare { } - controller_name="Lin"; + // Initialize the controller this way so that // there aren't any exceptions in the OS specific UI's Controller = (SparkleController) Activator.CreateInstance (