Skip to content

Commit c18d043

Browse files
committed
C#: Cleanup more files after failed autobuilder attempt
1 parent 6b28f33 commit c18d043

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

csharp/autobuilder/Semmle.Autobuild/Autobuilder.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,23 @@ BuildScript CheckExtractorRun(bool warnOnFailure) =>
262262
BuildScript.DeleteDirectory(Actions.GetEnvironmentVariable("TRAP_FOLDER"));
263263
var cleanSourceArchive =
264264
BuildScript.DeleteDirectory(Actions.GetEnvironmentVariable("SOURCE_ARCHIVE"));
265-
var cleanExtractorLog =
266-
BuildScript.DeleteFile(Extractor.GetCSharpLogPath());
265+
var tryCleanExtractorArgsLogs =
266+
BuildScript.Create(actions =>
267+
{
268+
foreach (var file in Extractor.GetCSharpArgsLogs())
269+
try
270+
{
271+
actions.FileDelete(file);
272+
}
273+
catch // lgtm[cs/catch-of-all-exceptions] lgtm[cs/empty-catch-block]
274+
{ }
275+
return 0;
276+
});
267277
var attemptExtractorCleanup =
268278
BuildScript.Try(cleanTrapFolder) &
269279
BuildScript.Try(cleanSourceArchive) &
270-
BuildScript.Try(cleanExtractorLog);
280+
tryCleanExtractorArgsLogs &
281+
BuildScript.DeleteFile(Extractor.GetCSharpLogPath());
271282

272283
/// <summary>
273284
/// Execute script `s` and check that the C# extractor has been executed.

csharp/extractor/Semmle.Extraction.CSharp/Analyser.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ public bool LogRoslynArgs(string[] roslynArgs, string extractorVersion)
450450
LogExtractorInfo(extractorVersion);
451451
Logger.Log(Severity.Info, $" Arguments to Roslyn: {string.Join(' ', roslynArgs)}");
452452

453-
var csharpLogDir = Extractor.GetCSharpLogDirectory();
454-
var tempFile = Path.Combine(csharpLogDir, $"csharp.{Path.GetRandomFileName()}.txt");
453+
var tempFile = Extractor.GetCSharpArgsLogPath(Path.GetRandomFileName());
455454

456455
bool argsWritten;
457456
using (var streamWriter = new StreamWriter(new FileStream(tempFile, FileMode.Append, FileAccess.Write)))
@@ -461,7 +460,7 @@ public bool LogRoslynArgs(string[] roslynArgs, string extractorVersion)
461460
}
462461

463462
var hash = FileUtils.ComputeFileHash(tempFile);
464-
var argsFile = Path.Combine(csharpLogDir, $"csharp.{hash}.txt");
463+
var argsFile = Extractor.GetCSharpArgsLogPath(hash);
465464

466465
if (argsWritten)
467466
Logger.Log(Severity.Info, $" Arguments have been written to {argsFile}");

csharp/extractor/Semmle.Extraction.CSharp/Extractor.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,19 @@ public static void ExtractStandalone(
391391
public static string GetCSharpLogPath() =>
392392
Path.Combine(GetCSharpLogDirectory(), "csharp.log");
393393

394-
public static string GetCSharpLogDirectory()
394+
/// <summary>
395+
/// Gets the path to a `csharp.{hash}.txt` file written to by the C# extractor.
396+
/// </summary>
397+
public static string GetCSharpArgsLogPath(string hash) =>
398+
Path.Combine(GetCSharpLogDirectory(), $"csharp.{hash}.txt");
399+
400+
/// <summary>
401+
/// Gets a list of all `csharp.{hash}.txt` files currently written to the log directory.
402+
/// </summary>
403+
public static IEnumerable<string> GetCSharpArgsLogs() =>
404+
Directory.EnumerateFiles(GetCSharpLogDirectory(), "csharp.*.txt");
405+
406+
static string GetCSharpLogDirectory()
395407
{
396408
string snapshot = Environment.GetEnvironmentVariable("ODASA_SNAPSHOT");
397409
string buildErrorDir = Environment.GetEnvironmentVariable("ODASA_BUILD_ERROR_DIR");

0 commit comments

Comments
 (0)