diff --git a/src/Microsoft.ComponentDetection.Contracts/FileComponentDetectorWithCleanup.cs b/src/Microsoft.ComponentDetection.Contracts/FileComponentDetectorWithCleanup.cs index 32ce18fc6..2a6e96dc5 100644 --- a/src/Microsoft.ComponentDetection.Contracts/FileComponentDetectorWithCleanup.cs +++ b/src/Microsoft.ComponentDetection.Contracts/FileComponentDetectorWithCleanup.cs @@ -160,10 +160,13 @@ private bool TryGetCleanupFileDirectory(ProcessRequest processRequest, out strin var (files, directories) = this.DirectoryUtilityService.GetFilesAndDirectories(root, patterns, depth); return (true, files, directories); } - catch (UnauthorizedAccessException e) + catch (Exception e) when (e is IOException or UnauthorizedAccessException) { - // log and return false if we are unauthorized to get files and directories - this.Logger.LogDebug(e, "Unauthorized to get files and directories for {Root}", root); + this.Logger.LogDebug( + "Failed to get files and directories for {Root}. Skipping cleanup. {ExceptionType}: {Message}", + root, + e.GetType().Name, + e.Message); return (false, new HashSet(), new HashSet()); } } diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/PipReportComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/pip/PipReportComponentDetector.cs index 4dd9a2b27..91d6f9a51 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/PipReportComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/PipReportComponentDetector.cs @@ -347,7 +347,18 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID { if (reportFile is not null && reportFile.Exists) { - reportFile.Delete(); + try + { + reportFile.Delete(); + } + catch (Exception e) when (e is IOException or UnauthorizedAccessException) + { + this.Logger.LogDebug( + "PipReport: Failed to delete report file {File}. {ExceptionType}: {Message}", + reportFile.FullName, + e.GetType().Name, + e.Message); + } } } }