Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #72 from kwirkykat/ArchiveSlashIssue
Browse files Browse the repository at this point in the history
Archive: Add handling for directory archive entries ending with a forward slash (Fixes #67)
  • Loading branch information
kwirkykat authored Jun 28, 2017
2 parents 96e0c00 + b184802 commit 6730d89
Show file tree
Hide file tree
Showing 5 changed files with 513 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DSCResource.Tests
*.vscode
33 changes: 29 additions & 4 deletions DscResources/MSFT_Archive/MSFT_Archive.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ $script:dscResourcesFolderFilePath = Split-Path $PSScriptRoot -Parent
$script:commonResourceHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'CommonResourceHelper.psm1'
Import-Module -Name $script:commonResourceHelperFilePath

# Import Microsoft.PowerShell.Utility for Get-FileHash
Import-Module -Name 'Microsoft.PowerShell.Utility'

# Localized messages for verbose and error statements in this resource
$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_Archive'

Expand Down Expand Up @@ -1083,6 +1086,28 @@ function Test-FileMatchesArchiveEntryByChecksum
return $fileMatchesArchiveEntry
}

<#
.SYNOPSIS
Tests if the given archive entry name represents a directory.
.PARAMETER ArchiveEntryName
The archive entry name to test.
#>
function Test-ArchiveEntryIsDirectory
{
[OutputType([Boolean])]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$ArchiveEntryName
)

return $ArchiveEntryName.EndsWith('\') -or $ArchiveEntryName.EndsWith('/')
}

<#
.SYNOPSIS
Tests if the specified archive exists in its expanded form at the destination.
Expand Down Expand Up @@ -1150,7 +1175,7 @@ function Test-ArchiveExistsAtDestination
{
Write-Verbose -Message ($script:localizedData.ItemWithArchiveEntryNameExists -f $archiveEntryPathAtDestination)

if ($archiveEntryFullName.EndsWith('\'))
if (Test-ArchiveEntryIsDirectory -ArchiveEntryName $archiveEntryFullName)
{
if (-not ($archiveEntryItemAtDestination -is [System.IO.DirectoryInfo]))
{
Expand Down Expand Up @@ -1261,7 +1286,7 @@ function Copy-ArchiveEntryToDestination

$archiveEntryFullName = Get-ArchiveEntryFullName -ArchiveEntry $ArchiveEntry

if ($archiveEntryFullName.EndsWith('\'))
if (Test-ArchiveEntryIsDirectory -ArchiveEntryName $archiveEntryFullName)
{
$null = New-Item -Path $DestinationPath -ItemType 'Directory'
}
Expand Down Expand Up @@ -1361,7 +1386,7 @@ function Expand-ArchiveToDestination
$archiveEntryFullName = Get-ArchiveEntryFullName -ArchiveEntry $archiveEntry
$archiveEntryPathAtDestination = Join-Path -Path $Destination -ChildPath $archiveEntryFullName

$archiveEntryIsDirectory = $archiveEntryFullName.EndsWith('\')
$archiveEntryIsDirectory = Test-ArchiveEntryIsDirectory -ArchiveEntryName $archiveEntryFullName

$archiveEntryItemAtDestination = Get-Item -LiteralPath $archiveEntryPathAtDestination -ErrorAction 'SilentlyContinue'

Expand Down Expand Up @@ -1533,7 +1558,7 @@ function Remove-ArchiveFromDestination
$archiveEntryFullName = Get-ArchiveEntryFullName -ArchiveEntry $archiveEntry
$archiveEntryPathAtDestination = Join-Path -Path $Destination -ChildPath $archiveEntryFullName

$archiveEntryIsDirectory = $archiveEntryFullName.EndsWith('\')
$archiveEntryIsDirectory = Test-ArchiveEntryIsDirectory -ArchiveEntryName $archiveEntryFullName

$itemAtDestination = Get-Item -LiteralPath $archiveEntryPathAtDestination -ErrorAction 'SilentlyContinue'

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,9 @@ The following parameters will be the same for each process in the set:

### Unreleased

* Archive:
* Added handling of directory archive entries that end with a foward slash

### 2.7.0.0

* MsiPackage
Expand Down
Loading

0 comments on commit 6730d89

Please sign in to comment.