File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed
autobuilder/Semmle.Autobuild Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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 } ") ;
Original file line number Diff line number Diff 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" ) ;
You can’t perform that action at this time.
0 commit comments