Fix host key check disabling/enabling by surrounding config with comments. Closes #390.

This commit is contained in:
Hylke Bons 2011-10-30 21:22:48 +00:00
parent 2f7227e799
commit 46d8eecb51
2 changed files with 33 additions and 20 deletions

View file

@ -81,6 +81,7 @@ namespace SparkleLib {
} }
} }
public override string CurrentRevision { public override string CurrentRevision {
get { get {
@ -526,7 +527,7 @@ namespace SparkleLib {
FillEmptyDirectories (child_path); FillEmptyDirectories (child_path);
} }
if (Directory.GetFiles (path).Length == 0) if (Directory.GetFiles (path).Length == 0 && !path.Equals (LocalPath))
File.Create (Path.Combine (path, ".empty")).Close (); File.Create (Path.Combine (path, ".empty")).Close ();
} }

View file

@ -140,8 +140,10 @@ namespace SparkleLib {
string ssh_config_path = Path.Combine (path, ".ssh"); string ssh_config_path = Path.Combine (path, ".ssh");
string ssh_config_file_path = SparkleHelpers.CombineMore (path, ".ssh", "config"); string ssh_config_file_path = SparkleHelpers.CombineMore (path, ".ssh", "config");
string ssh_config = Environment.NewLine + "Host " + host + string ssh_config = Environment.NewLine + "# <SparkleShare>" +
Environment.NewLine + "\tStrictHostKeyChecking no"; Environment.NewLine + "Host " + host +
Environment.NewLine + "\tStrictHostKeyChecking no" +
Environment.NewLine + "# </SparkleShare>";
if (!Directory.Exists (ssh_config_path)) if (!Directory.Exists (ssh_config_path))
Directory.CreateDirectory (ssh_config_path); Directory.CreateDirectory (ssh_config_path);
@ -152,16 +154,14 @@ namespace SparkleLib {
writer.Close (); writer.Close ();
} else { } else {
TextWriter writer = new StreamWriter (ssh_config_file_path); File.WriteAllText (ssh_config_file_path, ssh_config);
writer.WriteLine (ssh_config);
writer.Close ();
} }
UnixFileSystemInfo file_info = new UnixFileInfo (ssh_config_file_path); UnixFileSystemInfo file_info = new UnixFileInfo (ssh_config_file_path);
file_info.FileAccessPermissions = (FileAccessPermissions.UserRead | file_info.FileAccessPermissions = (FileAccessPermissions.UserRead |
FileAccessPermissions.UserWrite); FileAccessPermissions.UserWrite);
SparkleHelpers.DebugInfo ("Fetcher", "Disabled host key checking"); SparkleHelpers.DebugInfo ("Fetcher", "Disabled host key checking " + host);
} }
@ -176,25 +176,37 @@ namespace SparkleLib {
} }
string ssh_config_file_path = SparkleHelpers.CombineMore (path, ".ssh", "config"); string ssh_config_file_path = SparkleHelpers.CombineMore (path, ".ssh", "config");
string ssh_config = Environment.NewLine + "Host " + host +
Environment.NewLine + "\tStrictHostKeyChecking no";
if (File.Exists (ssh_config_file_path)) { if (File.Exists (ssh_config_file_path)) {
StreamReader reader = new StreamReader (ssh_config_file_path); string current_ssh_config = File.ReadAllText (ssh_config_file_path);
string current_ssh_config = reader.ReadToEnd ();
reader.Close ();
current_ssh_config = current_ssh_config.Remove ( current_ssh_config = current_ssh_config.Trim ();
current_ssh_config.IndexOf (ssh_config), ssh_config.Length); string [] lines = current_ssh_config.Split (Environment.NewLine.ToCharArray ());
string new_ssh_config = "";
bool in_sparkleshare_section = false;
bool has_some_ssh_config = new Regex (@"[a-z]").IsMatch (current_ssh_config); foreach (string line in lines) {
if (!has_some_ssh_config) { if (line.StartsWith ("# <SparkleShare>")) {
in_sparkleshare_section = true;
continue;
}
if (line.StartsWith ("# </SparkleShare>")) {
in_sparkleshare_section = false;
continue;
}
if (in_sparkleshare_section)
continue;
new_ssh_config += line + Environment.NewLine;
}
if (string.IsNullOrWhiteSpace (new_ssh_config)) {
File.Delete (ssh_config_file_path); File.Delete (ssh_config_file_path);
} else { } else {
TextWriter writer = new StreamWriter (ssh_config_file_path); File.WriteAllText (ssh_config_file_path, new_ssh_config.Trim ());
writer.WriteLine (current_ssh_config);
writer.Close ();
UnixFileSystemInfo file_info = new UnixFileInfo (ssh_config_file_path); UnixFileSystemInfo file_info = new UnixFileInfo (ssh_config_file_path);
file_info.FileAccessPermissions = (FileAccessPermissions.UserRead | file_info.FileAccessPermissions = (FileAccessPermissions.UserRead |
@ -202,7 +214,7 @@ namespace SparkleLib {
} }
} }
SparkleHelpers.DebugInfo ("Fetcher", "Enabled host key checking"); SparkleHelpers.DebugInfo ("Fetcher", "Enabled host key checking for " + host);
} }