From 4ecbaabdc7d7d55f55929720c3e8dd3e82d5dad8 Mon Sep 17 00:00:00 2001 From: gmipf Date: Fri, 16 Oct 2026 09:11:35 +0200 Subject: [PATCH 1/2] Remove the extraction folder also after a failed extraction Co-Authored-By: Claude Opus 5.5 --- BinaryObjectScanner/Scanner.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/BinaryObjectScanner/Scanner.cs b/BinaryObjectScanner/Scanner.cs index 35f13067..645fc0b4 100644 --- a/BinaryObjectScanner/Scanner.cs +++ b/BinaryObjectScanner/Scanner.cs @@ -405,11 +405,13 @@ private ProtectionDictionary GetInternalProtections(string fileName, Stream stre // 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,8 +428,14 @@ private ProtectionDictionary GetInternalProtections(string fileName, Stream stre // Append the values protections.Append(subProtections); } - - // If temp directory cleanup fails + } + catch (Exception ex) + { + if (_includeDebug) Console.Error.WriteLine(ex); + } + finally + { + // Remove the output path, also after a failed extraction try { if (Directory.Exists(tempPath)) @@ -438,10 +446,6 @@ private ProtectionDictionary GetInternalProtections(string fileName, Stream stre if (_includeDebug) Console.Error.WriteLine(ex); } } - catch (Exception ex) - { - if (_includeDebug) Console.Error.WriteLine(ex); - } } #endregion From 3866d2b910be61c7842cf50846f0ef4601196301 Mon Sep 17 00:00:00 2001 From: gmipf Date: Sat, 17 Oct 2026 00:27:18 +0200 Subject: [PATCH 2/2] Keep the original cleanup comment Co-Authored-By: Claude Opus 5.5 --- BinaryObjectScanner/Scanner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BinaryObjectScanner/Scanner.cs b/BinaryObjectScanner/Scanner.cs index 645fc0b4..bd464416 100644 --- a/BinaryObjectScanner/Scanner.cs +++ b/BinaryObjectScanner/Scanner.cs @@ -435,7 +435,7 @@ private ProtectionDictionary GetInternalProtections(string fileName, Stream stre } finally { - // Remove the output path, also after a failed extraction + // If temp directory cleanup fails try { if (Directory.Exists(tempPath))