Skip to content

Commit

Permalink
fix for missing empty directories when using ExtractToDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprabhat99 authored Jul 16, 2024
1 parent 6fcfae8 commit 188a426
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/SharpCompress/Archives/IArchiveExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 188a426

Please sign in to comment.