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

Commit cb9a6c8

Browse files
Merge pull request #746 from github-for-unity/fixes/symlinks-to-themselves-break-file-enumeration
Fix recursive filesystem enumeration
2 parents 951ffdb + bbe2ecc commit cb9a6c8

File tree

3 files changed

+56
-24
lines changed

3 files changed

+56
-24
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: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,16 @@ 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;
71-
if (isDefaultGitLfs)
72-
state.GitLfsExecutablePath = ProcessManager.FindExecutableInPath(installDetails.GitLfsExecutable, true, state.GitInstallationPath);
70+
if (!state.GitLfsExecutablePath.IsInitialized)
71+
{
72+
// look for it in the directory where we would install it from the bundle
73+
state.GitLfsExecutablePath = installDetails.GitLfsExecutablePath;
74+
}
7375

7476
state = ValidateGitLfsVersion(state);
7577

7678
if (state.GitLfsIsValid)
77-
{
78-
if (isDefaultGitLfs)
79-
state.GitLfsInstallationPath = state.GitInstallationPath;
80-
else
81-
state.GitLfsInstallationPath = state.GitLfsExecutablePath.Parent;
82-
}
79+
state.GitLfsInstallationPath = state.GitLfsExecutablePath.Parent;
8380

8481
return state;
8582
}
@@ -107,7 +104,7 @@ public GitInstallationState FindSystemGit(GitInstallationState state)
107104
state.GitLfsExecutablePath = gitLfsPath;
108105
state = ValidateGitLfsVersion(state);
109106
if (state.GitLfsIsValid)
110-
state.GitLfsInstallationPath = gitLfsPath.Parent;
107+
state.GitLfsInstallationPath = state.GitLfsExecutablePath.Parent;
111108
}
112109
return state;
113110
}
@@ -124,10 +121,7 @@ public GitInstallationState SetDefaultPaths(GitInstallationState state)
124121
if (!state.GitLfsIsValid)
125122
{
126123
state.GitLfsExecutablePath = installDetails.GitLfsExecutablePath;
127-
if (state.GitIsValid && state.GitInstallationPath != installDetails.GitInstallationPath)
128-
state.GitLfsInstallationPath = state.GitLfsExecutablePath.Parent;
129-
else
130-
state.GitLfsInstallationPath = installDetails.GitInstallationPath;
124+
state.GitLfsInstallationPath = state.GitLfsExecutablePath.Parent;
131125
state = ValidateGitLfsVersion(state);
132126
}
133127
return state;

src/GitHub.Api/Platform/ProcessEnvironment.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void Configure(ProcessStartInfo psi, NPath workingDirectory, bool dontSet
3737
var pathEntries = new List<string>();
3838
string separator = Environment.IsWindows ? ";" : ":";
3939

40+
NPath libexecPath = NPath.Default;
4041
if (Environment.GitInstallPath.IsInitialized)
4142
{
4243
var gitPathRoot = Environment.GitExecutablePath.Resolve().Parent.Parent;
@@ -53,9 +54,9 @@ public void Configure(ProcessStartInfo psi, NPath workingDirectory, bool dontSet
5354
binPath = baseExecPath.Combine("bin");
5455
}
5556

56-
var execPath = baseExecPath.Combine("libexec", "git-core");
57-
if (!execPath.DirectoryExists())
58-
execPath = NPath.Default;
57+
libexecPath = baseExecPath.Combine("libexec", "git-core");
58+
if (!libexecPath.DirectoryExists())
59+
libexecPath = NPath.Default;
5960

6061
if (Environment.IsWindows)
6162
{
@@ -66,17 +67,17 @@ public void Configure(ProcessStartInfo psi, NPath workingDirectory, bool dontSet
6667
pathEntries.Add(gitExecutableDir.ToString());
6768
}
6869

69-
if (execPath.IsInitialized)
70-
pathEntries.Add(execPath);
70+
if (libexecPath.IsInitialized)
71+
pathEntries.Add(libexecPath);
7172
pathEntries.Add(binPath);
7273

7374
// we can only set this env var if there is a libexec/git-core. git will bypass internally bundled tools if this env var
7475
// is set, which will break Apple's system git on certain tools (like osx-credentialmanager)
75-
if (execPath.IsInitialized)
76-
psi.EnvironmentVariables["GIT_EXEC_PATH"] = execPath.ToString();
76+
if (libexecPath.IsInitialized)
77+
psi.EnvironmentVariables["GIT_EXEC_PATH"] = libexecPath.ToString();
7778
}
7879

79-
if (Environment.GitLfsInstallPath.IsInitialized && Environment.GitInstallPath != Environment.GitLfsInstallPath)
80+
if (Environment.GitLfsInstallPath.IsInitialized && libexecPath != Environment.GitLfsInstallPath)
8081
{
8182
pathEntries.Add(Environment.GitLfsInstallPath);
8283
}

0 commit comments

Comments
 (0)