Skip to content

Commit 3b42dc2

Browse files
committed
C#: Also use AssemblyLookupLocation for framework dlls.
1 parent 99f0ed2 commit 3b42dc2

File tree

2 files changed

+21
-35
lines changed

2 files changed

+21
-35
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyLookupLocation.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
1010
/// Used to represent a path to an assembly or a directory containing assemblies
1111
/// and a selector function to determine which files to include, when indexing the assemblies.
1212
/// </summary>
13-
internal sealed class AssemblyLookupLocation(string p, Func<string, bool> includeFileName)
13+
internal sealed class AssemblyLookupLocation(string p, Func<string, bool> includeFileName, bool indexSubdirectories = true)
1414
{
1515
public string Path => p;
1616

@@ -26,23 +26,30 @@ public AssemblyLookupLocation(string p) : this(p, _ => true) { }
2626
/// <param name="dir">The directory to index.</param>
2727
private void AddReferenceDirectory(List<string> dllsToIndex, ILogger logger)
2828
{
29-
var dlls = new DirectoryInfo(p).EnumerateFiles("*.dll", new EnumerationOptions { RecurseSubdirectories = true, MatchCasing = MatchCasing.CaseInsensitive, AttributesToSkip = FileAttributes.None });
30-
if (!dlls.Any())
29+
try
3130
{
32-
logger.LogWarning($"AssemblyLookupLocation: No DLLs found in the path '{p}'.");
33-
return;
34-
}
35-
foreach (var dll in dlls)
36-
{
37-
if (includeFileName(dll.Name))
31+
var dlls = new DirectoryInfo(p).EnumerateFiles("*.dll", new EnumerationOptions { RecurseSubdirectories = indexSubdirectories, MatchCasing = MatchCasing.CaseInsensitive, AttributesToSkip = FileAttributes.None });
32+
if (!dlls.Any())
3833
{
39-
dllsToIndex.Add(dll.FullName);
34+
logger.LogWarning($"AssemblyLookupLocation: No DLLs found in the path '{p}'.");
35+
return;
4036
}
41-
else
37+
foreach (var dll in dlls)
4238
{
43-
logger.LogInfo($"AssemblyLookupLocation: Skipping {dll.FullName}.");
39+
if (includeFileName(dll.Name))
40+
{
41+
dllsToIndex.Add(dll.FullName);
42+
}
43+
else
44+
{
45+
logger.LogInfo($"AssemblyLookupLocation: Skipping {dll.FullName}.");
46+
}
4447
}
4548
}
49+
catch (Exception e)
50+
{
51+
logger.LogError($"AssemblyLookupLocation: Error while searching for DLLs in '{p}': {e.Message}");
52+
}
4653
}
4754

4855
/// <summary>

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -214,29 +214,8 @@ private HashSet<string> AddFrameworkDlls(HashSet<AssemblyLookupLocation> dllPath
214214
continue;
215215
}
216216

217-
if (useSubfolders)
218-
{
219-
dllPaths.Add(path);
220-
frameworkLocations.Add(path);
221-
continue;
222-
}
223-
224-
try
225-
{
226-
var dlls = Directory.GetFiles(path, "*.dll", new EnumerationOptions { RecurseSubdirectories = false, MatchCasing = MatchCasing.CaseInsensitive });
227-
if (dlls.Length == 0)
228-
{
229-
logger.LogError($"No DLLs found in specified framework reference path '{path}'.");
230-
continue;
231-
}
232-
233-
dllPaths.UnionWith(dlls.Select(x => new AssemblyLookupLocation(x)));
234-
frameworkLocations.UnionWith(dlls);
235-
}
236-
catch (Exception e)
237-
{
238-
logger.LogError($"Error while searching for DLLs in '{path}': {e.Message}");
239-
}
217+
dllPaths.Add(new AssemblyLookupLocation(path, _ => true, useSubfolders));
218+
frameworkLocations.Add(path);
240219
}
241220

242221
return frameworkLocations;

0 commit comments

Comments
 (0)