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) =>
262
262
BuildScript . DeleteDirectory ( Actions . GetEnvironmentVariable ( "TRAP_FOLDER" ) ) ;
263
263
var cleanSourceArchive =
264
264
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
+ } ) ;
267
277
var attemptExtractorCleanup =
268
278
BuildScript . Try ( cleanTrapFolder ) &
269
279
BuildScript . Try ( cleanSourceArchive ) &
270
- BuildScript . Try ( cleanExtractorLog ) ;
280
+ tryCleanExtractorArgsLogs &
281
+ BuildScript . DeleteFile ( Extractor . GetCSharpLogPath ( ) ) ;
271
282
272
283
/// <summary>
273
284
/// 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)
450
450
LogExtractorInfo ( extractorVersion ) ;
451
451
Logger . Log ( Severity . Info , $ " Arguments to Roslyn: { string . Join ( ' ' , roslynArgs ) } ") ;
452
452
453
- var csharpLogDir = Extractor . GetCSharpLogDirectory ( ) ;
454
- var tempFile = Path . Combine ( csharpLogDir , $ "csharp.{ Path . GetRandomFileName ( ) } .txt") ;
453
+ var tempFile = Extractor . GetCSharpArgsLogPath ( Path . GetRandomFileName ( ) ) ;
455
454
456
455
bool argsWritten ;
457
456
using ( var streamWriter = new StreamWriter ( new FileStream ( tempFile , FileMode . Append , FileAccess . Write ) ) )
@@ -461,7 +460,7 @@ public bool LogRoslynArgs(string[] roslynArgs, string extractorVersion)
461
460
}
462
461
463
462
var hash = FileUtils . ComputeFileHash ( tempFile ) ;
464
- var argsFile = Path . Combine ( csharpLogDir , $ "csharp. { hash } .txt" ) ;
463
+ var argsFile = Extractor . GetCSharpArgsLogPath ( hash ) ;
465
464
466
465
if ( argsWritten )
467
466
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(
391
391
public static string GetCSharpLogPath ( ) =>
392
392
Path . Combine ( GetCSharpLogDirectory ( ) , "csharp.log" ) ;
393
393
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 ( )
395
407
{
396
408
string snapshot = Environment . GetEnvironmentVariable ( "ODASA_SNAPSHOT" ) ;
397
409
string buildErrorDir = Environment . GetEnvironmentVariable ( "ODASA_BUILD_ERROR_DIR" ) ;
You can’t perform that action at this time.
0 commit comments