From 188a426ddea1979ab0400c248056ab97dedb36fe Mon Sep 17 00:00:00 2001 From: Alex Prabhat Bara <50404684+alexprabhat99@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:20:04 +0530 Subject: [PATCH 1/2] fix for missing empty directories when using ExtractToDirectory --- src/SharpCompress/Archives/IArchiveExtensions.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/SharpCompress/Archives/IArchiveExtensions.cs b/src/SharpCompress/Archives/IArchiveExtensions.cs index 382c3ddf..b47f3394 100644 --- a/src/SharpCompress/Archives/IArchiveExtensions.cs +++ b/src/SharpCompress/Archives/IArchiveExtensions.cs @@ -54,14 +54,23 @@ public static void ExtractToDirectory( var entry = entries.Entry; if (entry.IsDirectory) { + var dirPath = Path.Combine(destination, entry.Key.NotNull("Entry Key is null")); + if (Path.GetDirectoryName(dirPath + "/") is { } emptyDirectory && seenDirectories.Add(dirPath)) + { + Directory.CreateDirectory(emptyDirectory); + } continue; } - // Create each directory + // Create each directory if not already created var path = Path.Combine(destination, entry.Key.NotNull("Entry Key is null")); - if (Path.GetDirectoryName(path) is { } directory && seenDirectories.Add(path)) + if (Path.GetDirectoryName(path) is { } directory) { - Directory.CreateDirectory(directory); + if (!Directory.Exists(directory) && !seenDirectories.Contains(directory)) + { + Directory.CreateDirectory(directory); + seenDirectories.Add(directory); + } } // Write file From 004e0941d572da081d9542d181aa25188babee4e Mon Sep 17 00:00:00 2001 From: Alex Prabhat Bara <50404684+alexprabhat99@users.noreply.github.com> Date: Tue, 16 Jul 2024 20:12:01 +0530 Subject: [PATCH 2/2] code formatted using csharpier --- src/SharpCompress/Archives/IArchiveExtensions.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SharpCompress/Archives/IArchiveExtensions.cs b/src/SharpCompress/Archives/IArchiveExtensions.cs index b47f3394..4cba5463 100644 --- a/src/SharpCompress/Archives/IArchiveExtensions.cs +++ b/src/SharpCompress/Archives/IArchiveExtensions.cs @@ -55,7 +55,10 @@ public static void ExtractToDirectory( if (entry.IsDirectory) { var dirPath = Path.Combine(destination, entry.Key.NotNull("Entry Key is null")); - if (Path.GetDirectoryName(dirPath + "/") is { } emptyDirectory && seenDirectories.Add(dirPath)) + if ( + Path.GetDirectoryName(dirPath + "/") is { } emptyDirectory + && seenDirectories.Add(dirPath) + ) { Directory.CreateDirectory(emptyDirectory); }