Skip to content

Commit c5cf064

Browse files
authored
Merge pull request #15131 from tamasvajk/standalone/file-name
C#: Exclude not existing or problematic files from standalone extraction
2 parents d308bb4 + f9c6d5e commit c5cf064

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
7272
this.progressMonitor.FindingFiles(srcDir);
7373

7474

75-
var allFiles = GetAllFiles();
75+
var allFiles = GetAllFiles().ToList();
7676
var binaryFileExtensions = new HashSet<string>(new[] { ".dll", ".exe" }); // TODO: add more binary file extensions.
7777
var allNonBinaryFiles = allFiles.Where(f => !binaryFileExtensions.Contains(f.Extension.ToLowerInvariant())).ToList();
7878
var smallNonBinaryFiles = allNonBinaryFiles.SelectSmallFiles(progressMonitor).SelectFileNames();
@@ -439,6 +439,25 @@ private IEnumerable<FileInfo> GetAllFiles()
439439
files = files.Where(f => !f.FullName.StartsWith(options.DotNetPath, StringComparison.OrdinalIgnoreCase));
440440
}
441441

442+
files = files.Where(f =>
443+
{
444+
try
445+
{
446+
if (f.Exists)
447+
{
448+
return true;
449+
}
450+
451+
progressMonitor.Log(Severity.Warning, $"File {f.FullName} could not be processed.");
452+
return false;
453+
}
454+
catch (Exception ex)
455+
{
456+
progressMonitor.Log(Severity.Warning, $"File {f.FullName} could not be processed: {ex.Message}");
457+
return false;
458+
}
459+
});
460+
442461
files = new FilePathFilter(sourceDir, progressMonitor).Filter(files);
443462
return files;
444463
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Program
2+
{
3+
static void Main(string[] args)
4+
{
5+
}
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.100"
4+
}
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from create_database_utils import *
2+
3+
path = b'\xd2abcd.cs'
4+
5+
with open(path, 'w') as file:
6+
file.write('class X { }\n')
7+
8+
run_codeql_database_create([], lang="csharp", extra_args=["--extractor-option=buildless=true", "--extractor-option=cil=false"])

0 commit comments

Comments
 (0)