Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit a61a4ce

Browse files
committed
Fix recursive filesystem enumeration
The default GetFiles recursive method on Mono goes into an infinite loop when encountering symlinks that point to ./. Switch to yield for recursive filesystem enumeration so we can abort early Look for custom git-lfs executables in the same directory as git before looking recursively from the git installation path, as that can take a really long time and chances are git-lfs is right there in the same dir.
1 parent f2eeb5c commit a61a4ce

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/GitHub.Api/IO/FileSystem.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ public string GetFileNameWithoutExtension(string fileName)
143143
return Path.GetFileNameWithoutExtension(fileName);
144144
}
145145

146+
146147
public IEnumerable<string> GetFiles(string path)
147148
{
148-
return Directory.GetFiles(path);
149+
return GetFiles(path, "*");
149150
}
150151

151152
public IEnumerable<string> GetFiles(string path, string pattern)
@@ -155,7 +156,43 @@ public IEnumerable<string> GetFiles(string path, string pattern)
155156

156157
public IEnumerable<string> GetFiles(string path, string pattern, SearchOption searchOption)
157158
{
158-
return Directory.GetFiles(path, pattern, searchOption);
159+
foreach (var file in GetFiles(path, pattern))
160+
yield return file;
161+
162+
if (searchOption != SearchOption.AllDirectories)
163+
yield break;
164+
165+
#if ENABLE_MONO
166+
if (NPath.IsLinux)
167+
{
168+
try
169+
{
170+
path = Mono.Unix.UnixPath.GetCompleteRealPath(path);
171+
}
172+
catch
173+
{}
174+
}
175+
#endif
176+
foreach (var dir in GetDirectories(path))
177+
{
178+
var realdir = dir;
179+
#if ENABLE_MONO
180+
if (NPath.IsLinux)
181+
{
182+
try
183+
{
184+
realdir = Mono.Unix.UnixPath.GetCompleteRealPath(dir);
185+
}
186+
catch
187+
{}
188+
}
189+
#endif
190+
if (path != realdir)
191+
{
192+
foreach (var file in GetFiles(dir, pattern, searchOption))
193+
yield return file;
194+
}
195+
}
159196
}
160197

161198
public byte[] ReadAllBytes(string path)

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ public GitInstallationState VerifyGitSettings(GitInstallationState state = null)
6767
if (state.GitIsValid)
6868
state.GitInstallationPath = state.GitExecutablePath.Parent.Parent;
6969

70-
var isDefaultGitLfs = !state.GitLfsExecutablePath.IsInitialized || state.GitLfsInstallationPath == state.GitInstallationPath;
70+
var isDefaultGitLfs = !state.GitLfsExecutablePath.IsInitialized;
7171
if (isDefaultGitLfs)
72-
state.GitLfsExecutablePath = ProcessManager.FindExecutableInPath(installDetails.GitLfsExecutable, true, state.GitInstallationPath);
72+
{
73+
state.GitLfsExecutablePath = ProcessManager.FindExecutableInPath(installDetails.GitLfsExecutable, false, state.GitExecutablePath.Parent);
74+
if (!state.GitLfsExecutablePath.IsInitialized)
75+
state.GitLfsExecutablePath = ProcessManager.FindExecutableInPath(installDetails.GitLfsExecutable, true, state.GitInstallationPath);
76+
}
7377

7478
state = ValidateGitLfsVersion(state);
7579

0 commit comments

Comments
 (0)