Skip to content

Commit 77f2fd4

Browse files
committed
Be careful about known_hosts file existing with ssh record
Signed-off-by: Derrick Stolee <[email protected]>
1 parent 74741c4 commit 77f2fd4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Scalar.FunctionalTests/Tests/MultiEnlistmentTests/ScalarCloneFromGithub.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,18 @@ public void PartialCloneSsh()
3838
ProcessResult result = ProcessHelper.Run("ssh-keygen", "-H github.com");
3939

4040
string userDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
41-
this.fileSystem.AppendAllText(Path.Combine(userDir, ".ssh", "known_hosts"), result.Output);
41+
string sshDir = Path.Combine(userDir, ".ssh");
42+
43+
if (this.fileSystem.DirectoryExists(sshDir))
44+
{
45+
this.fileSystem.CreateDirectory(sshDir);
46+
}
47+
48+
string knownHosts = Path.Combine(sshDir, "known_hosts");
49+
if (this.fileSystem.FileExists(knownHosts) && !this.fileSystem.ReadAllText(knownHosts).Contains("github.com"))
50+
{
51+
this.fileSystem.AppendAllText(knownHosts, result.Output);
52+
}
4253

4354
ScalarFunctionalTestEnlistment enlistment = this.CreateNewEnlistment(
4455
url: MicrosoftScalarSsh,

0 commit comments

Comments
 (0)