diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/PipCommandService.cs b/src/Microsoft.ComponentDetection.Detectors/pip/PipCommandService.cs index aa24c002e..d6b495d46 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/PipCommandService.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/PipCommandService.cs @@ -131,7 +131,7 @@ private async Task ExecuteCommandAsync( var workingDir = new DirectoryInfo(this.pathUtilityService.GetParentDirectory(formattedPath)); CommandLineExecutionResult command; - var reportName = Path.GetRandomFileName(); + var reportName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".component-detection-pip-report.json"; var reportFile = new FileInfo(Path.Combine(workingDir.FullName, reportName)); string pipReportCommand; diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/PipReportComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/pip/PipReportComponentDetector.cs index dcb0dd3ea..59b68e0f1 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/PipReportComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/PipReportComponentDetector.cs @@ -22,6 +22,7 @@ public class PipReportComponentDetector : FileComponentDetector private const string PipReportOverrideBehaviorEnvVar = "PipReportOverrideBehavior"; private const string PipReportSkipFallbackOnFailureEnvVar = "PipReportSkipFallbackOnFailure"; private const string PipReportFileLevelTimeoutSecondsEnvVar = "PipReportFileLevelTimeoutSeconds"; + private const string PipReportPersistReportsEnvVar = "PipReportPersistReports"; private static readonly IList PipReportPreGeneratedFilePatterns = new List { "*.component-detection-pip-report.json", "component-detection-pip-report.json" }; @@ -300,11 +301,14 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID finally { // Clean up the report output JSON file so it isn't left on the machine. - foreach (var reportFile in reportFiles) + if (!this.envVarService.IsEnvironmentVariableValueTrue(PipReportPersistReportsEnvVar)) { - if (reportFile is not null && reportFile.Exists) + foreach (var reportFile in reportFiles) { - reportFile.Delete(); + if (reportFile is not null && reportFile.Exists) + { + reportFile.Delete(); + } } } }