mirror of
https://github.com/github/codeql.git
synced 2026-04-23 15:55:18 +02:00
C#: Use CODEQL_EXTRACTOR_CSHARP_SCRATCH_DIR instead of Path.GetTempPath
This commit is contained in:
@@ -479,7 +479,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
foreach (var b in sha.Take(8))
|
||||
sb.AppendFormat("{0:x2}", b);
|
||||
|
||||
return Path.Combine(Path.GetTempPath(), "GitHub", packages, sb.ToString());
|
||||
return Path.Combine(FileUtils.GetTemporaryWorkingDirectory(out var _), "GitHub", packages, sb.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using Semmle.Util;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
{
|
||||
@@ -51,7 +52,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
public IEnumerable<string> GenerateFiles(IEnumerable<string> cshtmls, IEnumerable<string> references, string workingDirectory)
|
||||
{
|
||||
var name = Guid.NewGuid().ToString("N").ToUpper();
|
||||
var tempPath = Path.GetTempPath();
|
||||
var tempPath = FileUtils.GetTemporaryWorkingDirectory(out var _);
|
||||
var analyzerConfig = Path.Combine(tempPath, $"{name}.txt");
|
||||
var dllPath = Path.Combine(tempPath, $"{name}.dll");
|
||||
var cscArgsPath = Path.Combine(tempPath, $"{name}.rsp");
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Semmle.Extraction
|
||||
|
||||
writerLazy = new Lazy<StreamWriter>(() =>
|
||||
{
|
||||
var tempPath = trap ?? Path.GetTempPath();
|
||||
var tempPath = trap ?? FileUtils.GetTemporaryWorkingDirectory(out var _);
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
@@ -7,8 +7,6 @@ namespace Semmle.Util
|
||||
public static string? GetExtractorOption(string name) =>
|
||||
Environment.GetEnvironmentVariable($"CODEQL_EXTRACTOR_CSHARP_OPTION_{name.ToUpper()}");
|
||||
|
||||
public static string? GetScratchDirectory() => Environment.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_SCRATCH_DIR");
|
||||
|
||||
public static int GetDefaultNumberOfThreads()
|
||||
{
|
||||
if (!int.TryParse(Environment.GetEnvironmentVariable("CODEQL_THREADS"), out var threads) || threads == -1)
|
||||
|
||||
@@ -144,10 +144,10 @@ namespace Semmle.Util
|
||||
return nested;
|
||||
}
|
||||
|
||||
public static string GetTemporaryWorkingDirectory(out bool shouldCleanUp)
|
||||
public static string GetTemporaryWorkingDirectory(Func<string, string?> getEnvironmentVariable, string lang, out bool shouldCleanUp)
|
||||
{
|
||||
shouldCleanUp = false;
|
||||
var tempFolder = EnvironmentVariables.GetScratchDirectory();
|
||||
var tempFolder = getEnvironmentVariable($"CODEQL_EXTRACTOR_{lang}_SCRATCH_DIR");
|
||||
|
||||
if (string.IsNullOrEmpty(tempFolder))
|
||||
{
|
||||
@@ -160,6 +160,9 @@ namespace Semmle.Util
|
||||
return tempFolder;
|
||||
}
|
||||
|
||||
public static string GetTemporaryWorkingDirectory(out bool shouldCleanUp) =>
|
||||
GetTemporaryWorkingDirectory(Environment.GetEnvironmentVariable, "CSHARP", out shouldCleanUp);
|
||||
|
||||
public static FileInfo CreateTemporaryFile(string extension, out bool shouldCleanUpContainingFolder)
|
||||
{
|
||||
var tempFolder = GetTemporaryWorkingDirectory(out shouldCleanUpContainingFolder);
|
||||
|
||||
Reference in New Issue
Block a user