From 0c23b23160dcf304e3748c1e4d2a467185a9df8b Mon Sep 17 00:00:00 2001 From: gmipf Date: Sat, 17 Oct 2026 01:44:24 +0200 Subject: [PATCH] Remove the extraction folder also after a failed extraction (#424) * Remove the extraction folder also after a failed extraction Co-Authored-By: Claude Opus 5.5 * Keep the original cleanup comment Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- BinaryObjectScanner/Scanner.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/BinaryObjectScanner/Scanner.cs b/BinaryObjectScanner/Scanner.cs index 35f13067..bd464416 100644 --- a/BinaryObjectScanner/Scanner.cs +++ b/BinaryObjectScanner/Scanner.cs @@ -405,11 +405,13 @@ namespace BinaryObjectScanner // If we're scanning archives if (_scanArchives && wrapper is IExtractable extractable) { + // Get the output path + string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + // If the extractable file itself fails try { - // Extract and get the output path - string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + // Extract to the output path Directory.CreateDirectory(tempPath); _ = extractable.Extract(tempPath, _includeDebug); @@ -426,7 +428,13 @@ namespace BinaryObjectScanner // Append the values protections.Append(subProtections); } - + } + catch (Exception ex) + { + if (_includeDebug) Console.Error.WriteLine(ex); + } + finally + { // If temp directory cleanup fails try { @@ -438,10 +446,6 @@ namespace BinaryObjectScanner if (_includeDebug) Console.Error.WriteLine(ex); } } - catch (Exception ex) - { - if (_includeDebug) Console.Error.WriteLine(ex); - } } #endregion