зеркало из https://github.com/github/codeql.git
Merge pull request #16312 from tamasvajk/fix/buildless/file-lookup
C#: Fix `global.json` and `packages.config` lookup
This commit is contained in:
Коммит
f29d2c21bd
|
@ -143,7 +143,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||
// See https://docs.microsoft.com/en-us/dotnet/core/tools/global-json
|
||||
var versions = new List<string>();
|
||||
|
||||
foreach (var path in files.Where(p => p.EndsWith("global.json", StringComparison.Ordinal)))
|
||||
foreach (var path in files.Where(p => string.Equals(FileUtils.SafeGetFileName(p, logger), "global.json", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -184,7 +184,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||
{
|
||||
try
|
||||
{
|
||||
var isPackagesConfig = file.EndsWith("packages.config", StringComparison.OrdinalIgnoreCase);
|
||||
var isPackagesConfig = string.Equals(FileUtils.SafeGetFileName(file, logger), "packages.config", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
foreach (ReadOnlySpan<char> line in unsafeFileReader.ReadLines(file))
|
||||
{
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||
|
||||
// group additional files by closes project file:
|
||||
var projects = fileProvider.Projects
|
||||
.Select(p => (File: p, Directory: SafeGetDirectoryName(p)))
|
||||
.Select(p => (File: p, Directory: FileUtils.SafeGetDirectoryName(p, logger)))
|
||||
.Where(p => p.Directory.Length > 0);
|
||||
|
||||
var groupedFiles = new Dictionary<string, List<string>>();
|
||||
|
@ -93,30 +93,6 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||
}
|
||||
}
|
||||
|
||||
private string SafeGetDirectoryName(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dir = Path.GetDirectoryName(fileName);
|
||||
if (dir is null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!dir.EndsWith(Path.DirectorySeparatorChar))
|
||||
{
|
||||
dir += Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogDebug($"Failed to get directory name for {fileName}: {ex.Message}");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract ICollection<string> AdditionalFiles { get; }
|
||||
|
||||
protected abstract string FileType { get; }
|
||||
|
|
|
@ -185,5 +185,42 @@ namespace Semmle.Util
|
|||
|
||||
return new FileInfo(outputPath);
|
||||
}
|
||||
|
||||
public static string SafeGetDirectoryName(string path, ILogger logger)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
if (dir is null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!dir.EndsWith(Path.DirectorySeparatorChar))
|
||||
{
|
||||
dir += Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogDebug($"Failed to get directory name for {path}: {ex.Message}");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static string? SafeGetFileName(string path, ILogger logger)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Path.GetFileName(path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogDebug($"Failed to get file name for {path}: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче