Skip to content

Commit

Permalink
Merge pull request #857 from alexprabhat99/master
Browse files Browse the repository at this point in the history
Fix for missing empty directories when using ExtractToDirectory
  • Loading branch information
adamhathcock authored Jul 18, 2024
2 parents 6fcfae8 + 004e094 commit 21e2983
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/SharpCompress/Archives/IArchiveExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,26 @@ 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
Expand Down

0 comments on commit 21e2983

Please sign in to comment.