Skip to content

Commit 86ca875

Browse files
committed
Limit search pattern and directory recursion
Narrow the scope of the search pattern to only include project files and limit directory recursion to 255 subdirectories to avoid infinite loops and subsequent `PathTooLongException`. May fix GH-4411.
1 parent 276336b commit 86ca875

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,17 @@ private IEnumerable<IFileInfo> GetProjectFiles(AssemblyInfoContext context)
190190
}
191191
else
192192
{
193-
foreach (var item in fileSystem.Directory.EnumerateFiles(workingDirectory, "*", SearchOption.AllDirectories).Where(IsSupportedProjectFile))
193+
var options = new EnumerationOptions
194194
{
195-
var assemblyInfoFile = fileSystem.FileInfo.New(item);
195+
RecurseSubdirectories = true,
196+
MaxRecursionDepth = 255
197+
};
198+
var projectFiles = fileSystem.Directory.EnumerateFiles(workingDirectory, ".*proj", options);
196199

197-
yield return assemblyInfoFile;
200+
foreach (var projectFile in projectFiles)
201+
{
202+
yield return fileSystem.FileInfo.New(projectFile);
198203
}
199204
}
200205
}
201-
202-
private static bool IsSupportedProjectFile(string fileName)
203-
{
204-
if (fileName.IsNullOrEmpty())
205-
{
206-
return false;
207-
}
208-
209-
return fileName.EndsWith(".csproj") ||
210-
fileName.EndsWith(".fsproj") ||
211-
fileName.EndsWith(".vbproj");
212-
}
213206
}

0 commit comments

Comments
 (0)