Skip to content

Commit

Permalink
Ensure destination directory exists
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Sep 12, 2021
1 parent 7bd9711 commit a8d065d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/SharpCompress/Common/ExtractionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@ public static void WriteEntryToDirectory(IEntry entry,
Action<string, ExtractionOptions?> write)
{
string destinationFileName;
string file = Path.GetFileName(entry.Key);
string fullDestinationDirectoryPath = Path.GetFullPath(destinationDirectory);

//check for trailing slash.
if (fullDestinationDirectoryPath[fullDestinationDirectoryPath.Length - 1] != Path.DirectorySeparatorChar)
{
fullDestinationDirectoryPath += Path.DirectorySeparatorChar;
}

if (!Directory.Exists(fullDestinationDirectoryPath))
{
throw new ExtractionException($"Directory does not exist to extract to: {fullDestinationDirectoryPath}");
}

options ??= new ExtractionOptions()
{
Overwrite = true
};

string file = Path.GetFileName(entry.Key);
if (options.ExtractFullPath)
{
string folder = Path.GetDirectoryName(entry.Key)!;
Expand Down

0 comments on commit a8d065d

Please sign in to comment.