mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
C#: Fix working directory structures in standalone
This commit is contained in:
@@ -52,7 +52,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
this.progressMonitor = new ProgressMonitor(logger);
|
||||
this.sourceDir = new DirectoryInfo(srcDir);
|
||||
|
||||
packageDirectory = new TemporaryDirectory(ComputeTempDirectory(sourceDir.FullName));
|
||||
packageDirectory = new TemporaryDirectory(ComputeTempDirectory(sourceDir.FullName, "packages"));
|
||||
legacyPackageDirectory = new TemporaryDirectory(ComputeTempDirectory(sourceDir.FullName, "legacypackages"));
|
||||
missingPackageDirectory = new TemporaryDirectory(ComputeTempDirectory(sourceDir.FullName, "missingpackages"));
|
||||
|
||||
@@ -467,7 +467,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
/// with this source tree. Use a SHA1 of the directory name.
|
||||
/// </summary>
|
||||
/// <returns>The full path of the temp directory.</returns>
|
||||
private static string ComputeTempDirectory(string srcDir, string packages = "packages")
|
||||
private static string ComputeTempDirectory(string srcDir, string subfolderName)
|
||||
{
|
||||
var bytes = Encoding.Unicode.GetBytes(srcDir);
|
||||
var sha = SHA1.HashData(bytes);
|
||||
@@ -475,7 +475,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
foreach (var b in sha.Take(8))
|
||||
sb.AppendFormat("{0:x2}", b);
|
||||
|
||||
return Path.Combine(FileUtils.GetTemporaryWorkingDirectory(out var _), "GitHub", packages, sb.ToString());
|
||||
return Path.Combine(FileUtils.GetTemporaryWorkingDirectory(out var _), sb.ToString(), subfolderName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -723,7 +723,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
Parallel.ForEach(notYetDownloadedPackages, new ParallelOptions { MaxDegreeOfParallelism = options.Threads }, package =>
|
||||
{
|
||||
progressMonitor.NugetInstall(package);
|
||||
using var tempDir = new TemporaryDirectory(ComputeTempDirectory(package));
|
||||
using var tempDir = new TemporaryDirectory(ComputeTempDirectory(package, "missingpackages_workingdir"));
|
||||
var success = dotnet.New(tempDir.DirInfo.FullName);
|
||||
if (!success)
|
||||
{
|
||||
|
||||
@@ -144,20 +144,40 @@ namespace Semmle.Util
|
||||
return nested;
|
||||
}
|
||||
|
||||
private static string? tempFolderPath = null;
|
||||
private static readonly object lockObject = new();
|
||||
|
||||
public static string GetTemporaryWorkingDirectory(Func<string, string?> getEnvironmentVariable, string lang, out bool shouldCleanUp)
|
||||
{
|
||||
shouldCleanUp = false;
|
||||
var tempFolder = getEnvironmentVariable($"CODEQL_EXTRACTOR_{lang}_SCRATCH_DIR");
|
||||
|
||||
if (string.IsNullOrEmpty(tempFolder))
|
||||
if (!string.IsNullOrEmpty(tempFolder))
|
||||
{
|
||||
return tempFolder;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(tempFolderPath))
|
||||
{
|
||||
shouldCleanUp = true;
|
||||
return tempFolderPath;
|
||||
}
|
||||
|
||||
lock (lockObject)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tempFolderPath))
|
||||
{
|
||||
shouldCleanUp = true;
|
||||
return tempFolderPath;
|
||||
}
|
||||
|
||||
var tempPath = Path.GetTempPath();
|
||||
var name = Guid.NewGuid().ToString("N").ToUpper();
|
||||
tempFolder = Path.Combine(tempPath, "GitHub", name);
|
||||
Directory.CreateDirectory(tempFolder);
|
||||
tempFolderPath = tempFolder;
|
||||
shouldCleanUp = true;
|
||||
return tempFolder;
|
||||
}
|
||||
|
||||
return tempFolder;
|
||||
}
|
||||
|
||||
public static string GetTemporaryWorkingDirectory(out bool shouldCleanUp) =>
|
||||
|
||||
Reference in New Issue
Block a user