From 131d4a0d818d52aadfd03ce791f356ba33dde89b Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Wed, 17 Jun 2026 16:03:08 +0200 Subject: [PATCH] C#: Fix the cs/path-combine code quality issues in the extractor. --- .../DependencyContainer.cs | 2 +- .../DependencyManager.cs | 4 ++-- .../Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs | 4 ++-- .../DotNetVersion.cs | 4 ++-- .../NugetPackageRestorer.cs | 8 ++++---- .../Runtime.cs | 2 +- .../Semmle.Extraction.CSharp.DependencyFetching/Sdk.cs | 2 +- .../DotnetSourceGeneratorWrapper.cs | 8 ++++---- .../DotnetSourceGeneratorWrapper/Razor.cs | 2 +- .../SourceGenerators/ImplicitUsingsGenerator.cs | 2 +- .../SourceGenerators/ResxGenerator.cs | 2 +- .../SourceGenerators/SourceGeneratorBase.cs | 2 +- .../Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs | 4 ++-- .../Semmle.Extraction.CSharp/Extractor/Context.cs | 2 +- .../Semmle.Extraction.CSharp/Extractor/CsProjFile.cs | 2 +- .../Semmle.Extraction.CSharp/Extractor/Extractor.cs | 8 ++++---- .../Semmle.Extraction.CSharp/Extractor/TracingAnalyser.cs | 2 +- .../Semmle.Extraction.CSharp/Extractor/TrapWriter.cs | 2 +- csharp/extractor/Semmle.Util.Tests/CanonicalPathCache.cs | 8 ++++---- csharp/extractor/Semmle.Util.Tests/LongPaths.cs | 8 ++++---- csharp/extractor/Semmle.Util/BuildActions.cs | 4 ++-- csharp/extractor/Semmle.Util/CanonicalPathCache.cs | 6 +++--- csharp/extractor/Semmle.Util/FileUtils.cs | 8 ++++---- 23 files changed, 48 insertions(+), 48 deletions(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyContainer.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyContainer.cs index b5abefb3a65..e99ab4c74f7 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyContainer.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyContainer.cs @@ -50,7 +50,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching return; } - var path = Path.Combine(p, ParseFilePath(d)); + var path = Path.Join(p, ParseFilePath(d)); Paths.Add(path); Packages.Add(GetPackageName(p)); } diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs index bc010e318c3..2706d526293 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs @@ -75,7 +75,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching } } - this.diagnosticsWriter = new DiagnosticsStream(Path.Combine( + this.diagnosticsWriter = new DiagnosticsStream(Path.Join( diagDirEnv ?? "", $"dependency-manager-{DateTime.UtcNow:yyyyMMddHHmm}-{Environment.ProcessId}.jsonc")); this.sourceDir = new DirectoryInfo(srcDir); @@ -327,7 +327,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching private void RemoveNugetPackageReference(string packagePrefix, ISet dllLocations) { var packageFolder = nugetPackageRestorer.PackageDirectory.DirInfo.FullName.ToLowerInvariant(); - var packagePathPrefix = Path.Combine(packageFolder, packagePrefix.ToLowerInvariant()); + var packagePathPrefix = Path.Join(packageFolder, packagePrefix.ToLowerInvariant()); var toRemove = dllLocations.Where(s => s.Path.StartsWith(packagePathPrefix, StringComparison.InvariantCultureIgnoreCase)); foreach (var path in toRemove) { diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs index 699e06d273c..f8505f8e8fe 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs @@ -31,7 +31,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching } } - private DotNet(ILogger logger, string? dotNetPath, TemporaryDirectory tempWorkingDirectory, DependabotProxy? dependabotProxy) : this(new DotNetCliInvoker(logger, Path.Combine(dotNetPath ?? string.Empty, "dotnet"), dependabotProxy), logger, dotNetPath is null, tempWorkingDirectory) { } + private DotNet(ILogger logger, string? dotNetPath, TemporaryDirectory tempWorkingDirectory, DependabotProxy? dependabotProxy) : this(new DotNetCliInvoker(logger, Path.Join(dotNetPath ?? string.Empty, "dotnet"), dependabotProxy), logger, dotNetPath is null, tempWorkingDirectory) { } internal static IDotNet Make(IDotNetCliInvoker dotnetCliInvoker, ILogger logger, bool runDotnetInfo) => new DotNet(dotnetCliInvoker, logger, runDotnetInfo); @@ -73,7 +73,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching var path = ".empty"; if (tempWorkingDirectory != null) { - path = Path.Combine(tempWorkingDirectory.ToString(), "emptyFakeDotnetRoot"); + path = Path.Join(tempWorkingDirectory.ToString(), "emptyFakeDotnetRoot"); Directory.CreateDirectory(path); } diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetVersion.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetVersion.cs index 31a4ac2292d..8ea710beb38 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetVersion.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetVersion.cs @@ -12,7 +12,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching private string FullVersion => version.ToString(); - public string FullPath => Path.Combine(dir, FullVersion); + public string FullPath => Path.Join(dir, FullVersion); /** * The full path to the reference assemblies for this runtime. @@ -33,7 +33,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching { directories[^2] = "packs"; directories[^1] = $"{directories[^1]}.Ref"; - return Path.Combine(string.Join(Path.DirectorySeparatorChar, directories), FullVersion, "ref"); + return Path.Join(string.Join(Path.DirectorySeparatorChar, directories), FullVersion, "ref"); } return null; } diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs index 7bafbb6f430..dd05c2ade86 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs @@ -209,7 +209,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching var paths = dependencies .Paths - .Select(d => Path.Combine(PackageDirectory.DirInfo.FullName, d)) + .Select(d => Path.Join(PackageDirectory.DirInfo.FullName, d)) .ToList(); assemblyLookupLocations.UnionWith(paths.Select(p => new AssemblyLookupLocation(p))); @@ -527,7 +527,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching var sb = new StringBuilder(); fallbackNugetFeeds.ForEach((feed, index) => sb.AppendLine($"")); - var nugetConfigPath = Path.Combine(folderPath, "nuget.config"); + var nugetConfigPath = Path.Join(folderPath, "nuget.config"); logger.LogInfo($"Creating fallback nuget.config file {nugetConfigPath}."); File.WriteAllText(nugetConfigPath, $""" @@ -1052,7 +1052,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching /// private static string ComputeTempDirectoryPath(string subfolderName) { - return Path.Combine(FileUtils.GetTemporaryWorkingDirectory(out _), subfolderName); + return Path.Join(FileUtils.GetTemporaryWorkingDirectory(out _), subfolderName); } /// @@ -1060,7 +1060,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching /// private static string ComputeTempDirectoryPath(string srcDir, string subfolderName) { - return Path.Combine(FileUtils.GetTemporaryWorkingDirectory(out _), FileUtils.ComputeHash(srcDir), subfolderName); + return Path.Join(FileUtils.GetTemporaryWorkingDirectory(out _), FileUtils.ComputeHash(srcDir), subfolderName); } } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Runtime.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Runtime.cs index 64c835d27fc..0ed2713b6f9 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Runtime.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Runtime.cs @@ -79,7 +79,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching var monoPath = FileUtils.FindProgramOnPath(Win32.IsWindows() ? "mono.exe" : "mono"); string[] monoDirs = monoPath is not null - ? [Path.GetFullPath(Path.Combine(monoPath, "..", "lib", "mono")), monoPath] + ? [Path.GetFullPath(Path.Join(monoPath, "..", "lib", "mono")), monoPath] : ["/usr/lib/mono", "/usr/local/mono", "/usr/local/bin/mono", @"C:\Program Files\Mono\lib\mono"]; var monoDir = monoDirs.FirstOrDefault(Directory.Exists); diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Sdk.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Sdk.cs index c4d1ba9ac08..20e188e625a 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Sdk.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Sdk.cs @@ -63,7 +63,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching return null; } - var path = Path.Combine(version.FullPath, "Roslyn", "bincore", "csc.dll"); + var path = Path.Join(version.FullPath, "Roslyn", "bincore", "csc.dll"); logger.LogDebug($"Source generator CSC: '{path}'"); if (!File.Exists(path)) { diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorWrapper/DotnetSourceGeneratorWrapper.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorWrapper/DotnetSourceGeneratorWrapper.cs index 68080244901..9518afac400 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorWrapper/DotnetSourceGeneratorWrapper.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorWrapper/DotnetSourceGeneratorWrapper.cs @@ -41,10 +41,10 @@ namespace Semmle.Extraction.CSharp.DependencyFetching .Replace('\\', '/'); // Ensure we're generating the same hash regardless of the OS var name = FileUtils.ComputeHash($"{relativePathToCsProj}\n{this.GetType().Name}"); using var tempDir = new TemporaryDirectory(Path.Join(FileUtils.GetTemporaryWorkingDirectory(out _), "source-generator"), "source generator temporary", logger); - var analyzerConfigPath = Path.Combine(tempDir.DirInfo.FullName, $"{name}.txt"); - var dllPath = Path.Combine(tempDir.DirInfo.FullName, $"{name}.dll"); - var cscArgsPath = Path.Combine(tempDir.DirInfo.FullName, $"{name}.rsp"); - var outputFolder = Path.Combine(targetDir, name); + var analyzerConfigPath = Path.Join(tempDir.DirInfo.FullName, $"{name}.txt"); + var dllPath = Path.Join(tempDir.DirInfo.FullName, $"{name}.dll"); + var cscArgsPath = Path.Join(tempDir.DirInfo.FullName, $"{name}.rsp"); + var outputFolder = Path.Join(targetDir, name); Directory.CreateDirectory(outputFolder); logger.LogInfo("Producing analyzer config content."); GenerateAnalyzerConfig(additionalFiles, csprojFile, analyzerConfigPath); diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorWrapper/Razor.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorWrapper/Razor.cs index 24423e6a129..fa509bb50b8 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorWrapper/Razor.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorWrapper/Razor.cs @@ -21,7 +21,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching throw new Exception("No SDK path available."); } - SourceGeneratorFolder = Path.Combine(sdkPath, "Sdks", "Microsoft.NET.Sdk.Razor", "source-generators"); + SourceGeneratorFolder = Path.Join(sdkPath, "Sdks", "Microsoft.NET.Sdk.Razor", "source-generators"); this.logger.LogInfo($"Razor source generator folder: {SourceGeneratorFolder}"); if (!Directory.Exists(SourceGeneratorFolder)) { diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/ImplicitUsingsGenerator.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/ImplicitUsingsGenerator.cs index f3bcdae3ac6..4d169b8c9f4 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/ImplicitUsingsGenerator.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/ImplicitUsingsGenerator.cs @@ -50,7 +50,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching if (usings.Count > 0) { var tempDir = GetTemporaryWorkingDirectory("implicitUsings"); - var path = Path.Combine(tempDir, "GlobalUsings.g.cs"); + var path = Path.Join(tempDir, "GlobalUsings.g.cs"); using (var writer = new StreamWriter(path)) { writer.WriteLine("// "); diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/ResxGenerator.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/ResxGenerator.cs index ff24bf0ea6f..da66ef27544 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/ResxGenerator.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/ResxGenerator.cs @@ -32,7 +32,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching var nugetFolder = nugetPackageRestorer.TryRestore("Microsoft.CodeAnalysis.ResxSourceGenerator"); if (nugetFolder is not null) { - sourceGeneratorFolder = System.IO.Path.Combine(nugetFolder, "analyzers", "dotnet", "cs"); + sourceGeneratorFolder = System.IO.Path.Join(nugetFolder, "analyzers", "dotnet", "cs"); } } catch (Exception e) diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/SourceGeneratorBase.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/SourceGeneratorBase.cs index 36890f2d89c..545497dbd2b 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/SourceGeneratorBase.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/SourceGeneratorBase.cs @@ -35,7 +35,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching /// protected string GetTemporaryWorkingDirectory(string subfolder) { - var temp = Path.Combine(tempWorkingDirectory.ToString(), subfolder); + var temp = Path.Join(tempWorkingDirectory.ToString(), subfolder); Directory.CreateDirectory(temp); return temp; diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs index 5429f2bba07..d894cbbe2ec 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs @@ -67,7 +67,7 @@ namespace Semmle.Extraction.CSharp return; } - var mscorlibExists = File.Exists(Path.Combine(compilerDir, "mscorlib.dll")); + var mscorlibExists = File.Exists(Path.Join(compilerDir, "mscorlib.dll")); if (specifiedFramework is null && mscorlibExists) { @@ -107,7 +107,7 @@ namespace Semmle.Extraction.CSharp /// /// The file csc.rsp. /// - private string CscRsp => Path.Combine(FrameworkPath, csc_rsp); + private string CscRsp => Path.Join(FrameworkPath, csc_rsp); /// /// Should we skip extraction? diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs index c3752165204..829561d37ae 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs @@ -680,7 +680,7 @@ namespace Semmle.Extraction.CSharp { try { - var fullPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(mappedFromPath)!, mappedToPath)); + var fullPath = Path.GetFullPath(Path.Join(Path.GetDirectoryName(mappedFromPath)!, mappedToPath)); ExtractionContext.Logger.LogDebug($"Found relative path in line mapping: '{mappedToPath}', interpreting it as '{fullPath}'"); mappedToPath = fullPath; diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CsProjFile.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CsProjFile.cs index 665eb0bf346..d130e4002ff 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CsProjFile.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CsProjFile.cs @@ -159,7 +159,7 @@ namespace Semmle.Extraction.CSharp return null; } - return Path.GetFullPath(Path.Combine(projDir?.FullName ?? string.Empty, Path.DirectorySeparatorChar == '/' ? file.Replace("\\", "/") : file)); + return Path.GetFullPath(Path.Join(projDir?.FullName ?? string.Empty, Path.DirectorySeparatorChar == '/' ? file.Replace("\\", "/") : file)); } private readonly string[] references; diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Extractor.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Extractor.cs index 69aa7c47909..659fea49e9b 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Extractor.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Extractor.cs @@ -210,7 +210,7 @@ namespace Semmle.Extraction.CSharp TracingAnalyser.GetOutputName(compilation, args), compilation, generatedSyntaxTrees, - Path.Combine(compilationIdentifierPath, diagnosticName), + Path.Join(compilationIdentifierPath, diagnosticName), options), () => { }); @@ -377,7 +377,7 @@ namespace Semmle.Extraction.CSharp else { var composed = referencePaths.Value - .Select(path => Path.Combine(path, clref.Reference)) + .Select(path => Path.Join(path, clref.Reference)) .Where(path => File.Exists(path)) .Select(path => analyser.PathCache.GetCanonicalPath(path)) .FirstOrDefault(); @@ -559,13 +559,13 @@ namespace Semmle.Extraction.CSharp /// Gets the path to the `csharp.log` file written to by the C# extractor. /// public static string GetCSharpLogPath() => - Path.Combine(GetCSharpLogDirectory(), "csharp.log"); + Path.Join(GetCSharpLogDirectory(), "csharp.log"); /// /// Gets the path to a `csharp.{hash}.txt` file written to by the C# extractor. /// public static string GetCSharpArgsLogPath(string hash) => - Path.Combine(GetCSharpLogDirectory(), $"csharp.{hash}.txt"); + Path.Join(GetCSharpLogDirectory(), $"csharp.{hash}.txt"); /// /// Gets a list of all `csharp.{hash}.txt` files currently written to the log directory. diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TracingAnalyser.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TracingAnalyser.cs index 9f2a1256f1a..b66dba798dd 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TracingAnalyser.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TracingAnalyser.cs @@ -131,7 +131,7 @@ namespace Semmle.Extraction.CSharp return Path.ChangeExtension(entryPointFilename, ".exe"); } - return Path.Combine(commandLineArguments.OutputDirectory, commandLineArguments.OutputFileName); + return Path.Join(commandLineArguments.OutputDirectory, commandLineArguments.OutputFileName); } private int LogDiagnostics() diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TrapWriter.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TrapWriter.cs index 42e933c8eaf..ea6adb22642 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TrapWriter.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TrapWriter.cs @@ -61,7 +61,7 @@ namespace Semmle.Extraction.CSharp * Although GetRandomFileName() is cryptographically secure, * there's a tiny chance the file could already exists. */ - tmpFile = Path.Combine(tempPath, Path.GetRandomFileName()); + tmpFile = Path.Join(tempPath, Path.GetRandomFileName()); } while (File.Exists(tmpFile)); diff --git a/csharp/extractor/Semmle.Util.Tests/CanonicalPathCache.cs b/csharp/extractor/Semmle.Util.Tests/CanonicalPathCache.cs index 313b949810d..e75821a4cb1 100644 --- a/csharp/extractor/Semmle.Util.Tests/CanonicalPathCache.cs +++ b/csharp/extractor/Semmle.Util.Tests/CanonicalPathCache.cs @@ -82,13 +82,13 @@ namespace SemmleTests.Semmle.Util [Fact] public void CanonicalPathMissingFile() { - Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), "NOSUCHFILE"), cache.GetCanonicalPath("NOSUCHFILE")); + Assert.Equal(Path.Join(Directory.GetCurrentDirectory(), "NOSUCHFILE"), cache.GetCanonicalPath("NOSUCHFILE")); } [Fact] public void CanonicalPathMissingAbsolutePath() { - Assert.Equal(Path.Combine(root, "no", "such", "file"), cache.GetCanonicalPath(Path.Combine(root, "no", "such", "file"))); + Assert.Equal(Path.Join(root, "no", "such", "file"), cache.GetCanonicalPath(Path.Join(root, "no", "such", "file"))); if (Win32.IsWindows()) Assert.Equal(@"C:\Windows\no\such\file", cache.GetCanonicalPath(@"C:\windOws\no\such\file")); @@ -97,7 +97,7 @@ namespace SemmleTests.Semmle.Util [Fact] public void CanonicalPathMissingRelativePath() { - Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), "NO", "SUCH"), cache.GetCanonicalPath(Path.Combine("NO", "SUCH"))); + Assert.Equal(Path.Join(Directory.GetCurrentDirectory(), "NO", "SUCH"), cache.GetCanonicalPath(Path.Join("NO", "SUCH"))); } [Fact] @@ -125,7 +125,7 @@ namespace SemmleTests.Semmle.Util public void CanonicalPathDots() { var abcPath = Path.GetFullPath("abc"); - Assert.Equal(abcPath, cache.GetCanonicalPath(Path.Combine("foo", ".", "..", "abc"))); + Assert.Equal(abcPath, cache.GetCanonicalPath(Path.Join("foo", ".", "..", "abc"))); } [Fact] diff --git a/csharp/extractor/Semmle.Util.Tests/LongPaths.cs b/csharp/extractor/Semmle.Util.Tests/LongPaths.cs index 90607bc8f02..381fd97e214 100644 --- a/csharp/extractor/Semmle.Util.Tests/LongPaths.cs +++ b/csharp/extractor/Semmle.Util.Tests/LongPaths.cs @@ -14,20 +14,20 @@ namespace SemmleTests.Semmle.Util public sealed class LongPaths { private static readonly string tmpDir = Environment.GetEnvironmentVariable("TEST_TMPDIR") ?? Path.GetTempPath(); - private static readonly string longPathDir = Path.Combine(tmpDir, "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + private static readonly string longPathDir = Path.Join(tmpDir, "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "ccccccccccccccccccccccccccccccc", "ddddddddddddddddddddddddddddddddddddd", "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "fffffffffffffffffffffffffffffffff", "ggggggggggggggggggggggggggggggggggg", "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"); private static string MakeLongPath() { var uniquePostfix = Guid.NewGuid().ToString("N"); - return Path.Combine(longPathDir, $"iiiiiiiiiiiiiiii{uniquePostfix}.txt"); + return Path.Join(longPathDir, $"iiiiiiiiiiiiiiii{uniquePostfix}.txt"); } private static string MakeShortPath() { var uniquePostfix = Guid.NewGuid().ToString("N"); - return Path.Combine(tmpDir, $"test{uniquePostfix}.txt"); + return Path.Join(tmpDir, $"test{uniquePostfix}.txt"); } public LongPaths() @@ -62,7 +62,7 @@ namespace SemmleTests.Semmle.Util [Fact] public void ParentDirectory() { - Assert.Equal("abc", Path.GetDirectoryName(Path.Combine("abc", "def"))); + Assert.Equal("abc", Path.GetDirectoryName(Path.Join("abc", "def"))); Assert.Equal(Win32.IsWindows() ? "\\" : "/", Path.GetDirectoryName($@"{Path.DirectorySeparatorChar}def")); Assert.Equal("", Path.GetDirectoryName(@"def")); diff --git a/csharp/extractor/Semmle.Util/BuildActions.cs b/csharp/extractor/Semmle.Util/BuildActions.cs index 09696564efc..94e4abf9997 100644 --- a/csharp/extractor/Semmle.Util/BuildActions.cs +++ b/csharp/extractor/Semmle.Util/BuildActions.cs @@ -137,7 +137,7 @@ namespace Semmle.Util bool IsMonoInstalled(); /// - /// Combine path segments, Path.Combine(). + /// Combine path segments, Path.Join(). /// /// The parts of the path. /// The combined path. @@ -293,7 +293,7 @@ namespace Semmle.Util } } - string IBuildActions.PathCombine(params string[] parts) => Path.Combine(parts); + string IBuildActions.PathCombine(params string[] parts) => Path.Join(parts); void IBuildActions.WriteAllText(string filename, string contents) => File.WriteAllText(filename, contents); diff --git a/csharp/extractor/Semmle.Util/CanonicalPathCache.cs b/csharp/extractor/Semmle.Util/CanonicalPathCache.cs index d3cbf41fa10..2dc04e074f6 100644 --- a/csharp/extractor/Semmle.Util/CanonicalPathCache.cs +++ b/csharp/extractor/Semmle.Util/CanonicalPathCache.cs @@ -43,7 +43,7 @@ namespace Semmle.Util var parent = Directory.GetParent(path); return parent is not null ? - Path.Combine(cache.GetCanonicalPath(parent.FullName), Path.GetFileName(path)) : + Path.Join(cache.GetCanonicalPath(parent.FullName), Path.GetFileName(path)) : path.ToUpperInvariant(); } } @@ -138,12 +138,12 @@ namespace Semmle.Util var entries = Directory.GetFileSystemEntries(parentPath, name); return entries.Length == 1 ? entries[0] - : Path.Combine(parentPath, name); + : Path.Join(parentPath, name); } catch // lgtm[cs/catch-of-all-exceptions] { // IO error or security error querying directory. - return Path.Combine(parentPath, name); + return Path.Join(parentPath, name); } } } diff --git a/csharp/extractor/Semmle.Util/FileUtils.cs b/csharp/extractor/Semmle.Util/FileUtils.cs index ce157a8268a..4706c18f72b 100644 --- a/csharp/extractor/Semmle.Util/FileUtils.cs +++ b/csharp/extractor/Semmle.Util/FileUtils.cs @@ -82,7 +82,7 @@ namespace Semmle.Util { exes = new[] { prog }; } - var candidates = paths?.Where(path => exes.Any(exe0 => File.Exists(Path.Combine(path, exe0)))); + var candidates = paths?.Where(path => exes.Any(exe0 => File.Exists(Path.Join(path, exe0)))); return candidates?.FirstOrDefault(); } @@ -179,7 +179,7 @@ namespace Semmle.Util { innerpath = ConvertPathToSafeRelativePath(innerpath); - nested = Path.Combine(outerpath, innerpath); + nested = Path.Join(outerpath, innerpath); } try { @@ -203,7 +203,7 @@ namespace Semmle.Util { var tempPath = Path.GetTempPath(); var name = Guid.NewGuid().ToString("N").ToUpper(); - var tempFolder = Path.Combine(tempPath, "GitHub", name); + var tempFolder = Path.Join(tempPath, "GitHub", name); Directory.CreateDirectory(tempFolder); return tempFolder; }); @@ -231,7 +231,7 @@ namespace Semmle.Util string outputPath; do { - outputPath = Path.Combine(tempFolder, Path.GetRandomFileName() + extension); + outputPath = Path.Join(tempFolder, Path.GetRandomFileName() + extension); } while (File.Exists(outputPath));