C#: Fix working directory structures in standalone

This commit is contained in:
Tamas Vajk
2023-12-19 12:54:00 +01:00
parent f50817e92a
commit dd64b436c0
2 changed files with 28 additions and 8 deletions

View File

@@ -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) =>