Skip to content

Commit 4f559b7

Browse files
authored
Merge pull request #17 from KirkMunro/issue_3
Fixed Compress-Archive so that it can compress to a custom PSDrive
2 parents 89951b8 + a91c893 commit 4f559b7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ function Compress-Archive
8383
)
8484

8585
BEGIN
86-
{
86+
{
87+
# Ensure the destination path is in a non-PS-specific format
88+
$DestinationPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($DestinationPath)
89+
8790
$inputPaths = @()
8891
$destinationParentDir = [system.IO.Path]::GetDirectoryName($DestinationPath)
8992
if($null -eq $destinationParentDir)

Tests/Pester.Commands.Cmdlets.Archive.Tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,19 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "BVT" {
706706
try { Expand-Archive -Path $sourcePath -DestinationPath $destinationPath; throw "Expand-Archive did NOT throw expected error" }
707707
catch { $_.FullyQualifiedErrorId | Should Be "InvalidDirectoryPath,Expand-Archive" }
708708
}
709+
710+
It "Validate that you can compress an archive to a custom PSDrive using the Compress-Archive cmdlet" {
711+
$sourcePath = "$TestDrive\SourceDir\ChildDir-1\Sample-3.txt"
712+
$destinationDriveName = 'CompressArchivePesterTest'
713+
$destinationDrive = New-PSDrive -Name $destinationDriveName -PSProvider FileSystem -Root $TestDrive -Scope Global
714+
$destinationPath = "${destinationDriveName}:\CompressToPSDrive.zip"
715+
try {
716+
Compress-Archive -Path $sourcePath -DestinationPath $destinationPath
717+
$destinationPath | Should Exist
718+
} finally {
719+
Remove-PSDrive -LiteralName $destinationDriveName
720+
}
721+
}
709722
}
710723

711724
Context "Expand-Archive - functional test cases" {

0 commit comments

Comments
 (0)