Skip to content

Commit 12663b5

Browse files
committed
C# Only remove temp files for MVC view generation if needed
1 parent 048b372 commit 12663b5

File tree

1 file changed

+10
-7
lines changed
  • csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching

1 file changed

+10
-7
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Razor.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static void GenerateAnalyzerConfig(IEnumerable<string> cshtmls, string a
5555
public IEnumerable<string> GenerateFiles(IEnumerable<string> cshtmls, IEnumerable<string> references, string workingDirectory)
5656
{
5757
var name = Guid.NewGuid().ToString("N").ToUpper();
58-
var tempPath = FileUtils.GetTemporaryWorkingDirectory(out var _);
58+
var tempPath = FileUtils.GetTemporaryWorkingDirectory(out var shouldCleanUp);
5959
var analyzerConfig = Path.Combine(tempPath, $"{name}.txt");
6060
var dllPath = Path.Combine(tempPath, $"{name}.dll");
6161
var cscArgsPath = Path.Combine(tempPath, $"{name}.rsp");
@@ -105,21 +105,24 @@ public IEnumerable<string> GenerateFiles(IEnumerable<string> cshtmls, IEnumerabl
105105
}
106106
finally
107107
{
108-
DeleteFile(analyzerConfig);
109-
DeleteFile(dllPath);
110-
DeleteFile(cscArgsPath);
108+
if (shouldCleanUp)
109+
{
110+
DeleteFile(analyzerConfig);
111+
DeleteFile(dllPath);
112+
DeleteFile(cscArgsPath);
113+
}
111114
}
112115
}
113116

114-
private static void DeleteFile(string path)
117+
private void DeleteFile(string path)
115118
{
116119
try
117120
{
118121
File.Delete(path);
119122
}
120-
catch
123+
catch (Exception exc)
121124
{
122-
// Ignore
125+
logger.LogWarning($"Failed to delete file {path}: {exc}");
123126
}
124127
}
125128
}

0 commit comments

Comments
 (0)