C# Only remove temp files for MVC view generation if needed

This commit is contained in:
Tamas Vajk
2024-02-14 17:00:37 +01:00
parent 048b3727f5
commit 12663b58f1

View File

@@ -55,7 +55,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 = FileUtils.GetTemporaryWorkingDirectory(out var _);
var tempPath = FileUtils.GetTemporaryWorkingDirectory(out var shouldCleanUp);
var analyzerConfig = Path.Combine(tempPath, $"{name}.txt");
var dllPath = Path.Combine(tempPath, $"{name}.dll");
var cscArgsPath = Path.Combine(tempPath, $"{name}.rsp");
@@ -105,21 +105,24 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
}
finally
{
DeleteFile(analyzerConfig);
DeleteFile(dllPath);
DeleteFile(cscArgsPath);
if (shouldCleanUp)
{
DeleteFile(analyzerConfig);
DeleteFile(dllPath);
DeleteFile(cscArgsPath);
}
}
}
private static void DeleteFile(string path)
private void DeleteFile(string path)
{
try
{
File.Delete(path);
}
catch
catch (Exception exc)
{
// Ignore
logger.LogWarning($"Failed to delete file {path}: {exc}");
}
}
}