Skip to content

Commit

Permalink
Merge pull request #256 from bielawb/dev
Browse files Browse the repository at this point in the history
Updating commands to use -LiteralPath instead of -Path (Fixes #255)
  • Loading branch information
kwirkykat authored Dec 8, 2016
2 parents f0abfb6 + 2b35def commit e5a82a8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
36 changes: 18 additions & 18 deletions DSCResources/MSFT_xArchive/MSFT_xArchive.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function Set-TargetResource

Write-Verbose -Message $LocalizedData.ConfigurationStarted

if (-not (Test-Path -Path $Destination))
if (-not (Test-Path -LiteralPath $Destination))
{
New-Item -Path $Destination -ItemType Directory | Out-Null
}
Expand Down Expand Up @@ -245,7 +245,7 @@ function Set-TargetResource
if (-not $Checksum -and $PSCmdlet.ShouldProcess(($LocalizedData.RemoveFile -f $archiveEntryDestinationPath), $null, $null))
{
Write-Verbose -Message ($LocalizedData.RemovingDir -f $archiveEntryDestinationPath)
Remove-Item -Path $archiveEntryDestinationPath
Remove-Item -LiteralPath $archiveEntryDestinationPath
continue
}

Expand All @@ -254,7 +254,7 @@ function Set-TargetResource
if ((Test-FileHashMatchesArchiveEntryHash -FilePath $archiveEntryDestinationPath -ArchiveEntry $archiveEntry -HashAlgorithmName $Checksum) -and $PSCmdlet.ShouldProcess(($LocalizedData.RemoveFile -f $archiveEntryDestinationPath), $null, $null))
{
Write-Verbose -Message ($LocalizedData.HashesOfExistingAndZipFilesMatchRemoving)
Remove-Item -Path $archiveEntryDestinationPath
Remove-Item -LiteralPath $archiveEntryDestinationPath
}
else
{
Expand All @@ -267,7 +267,7 @@ function Set-TargetResource
if ($relevantTimestamp.Equals($archiveEntry.LastWriteTime.DateTime) -and $PSCmdlet.ShouldProcess(($LocalizedData.RemoveFile -f $archiveEntryDestinationPath), $null, $null))
{
Write-Verbose -Message ($LocalizedData.InSetTargetResourceexistsselectedtimestampmatched -f $archiveEntryDestinationPath, $Checksum)
Remove-Item -Path $archiveEntryDestinationPath
Remove-Item -LiteralPath $archiveEntryDestinationPath
}
else
{
Expand Down Expand Up @@ -296,7 +296,7 @@ function Set-TargetResource
-and $PSCmdlet.ShouldProcess(($LocalizedData.RemoveDirectory -f $fileInfoAtDestinationPath), $null, $null))
{
Write-Verbose -Message ($LocalizedData.ExistingaAppearsToBeAneEmptyDirectoryRemovingit -f $fileInfoAtDestinationPath)
Remove-Item -Path $fileInfoAtDestinationPath
Remove-Item -LiteralPath $fileInfoAtDestinationPath
}
}

Expand Down Expand Up @@ -388,7 +388,7 @@ function Set-TargetResource

if ($PSCmdlet.ShouldProcess(($LocalizedData.RemoveDirectory -f $archiveEntryDestinationPath), $null, $null))
{
Remove-Item -Path $archiveEntryDestinationPath -Recurse -Force | Out-Null
Remove-Item -LiteralPath $archiveEntryDestinationPath -Recurse -Force | Out-Null
}
}
else
Expand All @@ -400,7 +400,7 @@ function Set-TargetResource
}

$archiveEntryDestinationParentPath = Split-Path -Path $archiveEntryDestinationPath
if (-not (Test-Path $archiveEntryDestinationParentPath) -and $PSCmdlet.ShouldProcess(($LocalizedData.MakeDirectory -f $archiveEntryDestinationParentPath), $null, $null))
if (-not (Test-Path -LiteralPath $archiveEntryDestinationParentPath) -and $PSCmdlet.ShouldProcess(($LocalizedData.MakeDirectory -f $archiveEntryDestinationParentPath), $null, $null))
{
<#
TODO: This is an edge case we need to revisit. We should be correctly handling wrong file types along
Expand Down Expand Up @@ -451,9 +451,9 @@ function Set-TargetResource
$updatedTimestamp = $archiveEntry.LastWriteTime.DateTime
$archiveEntry.ExistingItemTimestamp = $updatedTimestamp

Set-ItemProperty -Path $archiveEntryDestinationPath -Name 'LastWriteTime' -Value $updatedTimestamp
Set-ItemProperty -Path $archiveEntryDestinationPath -Name 'LastAccessTime' -Value $updatedTimestamp
Set-ItemProperty -Path $archiveEntryDestinationPath -Name 'CreationTime' -Value $updatedTimestamp
Set-ItemProperty -LiteralPath $archiveEntryDestinationPath -Name 'LastWriteTime' -Value $updatedTimestamp
Set-ItemProperty -LiteralPath $archiveEntryDestinationPath -Name 'LastAccessTime' -Value $updatedTimestamp
Set-ItemProperty -LiteralPath $archiveEntryDestinationPath -Name 'CreationTime' -Value $updatedTimestamp
}
}
finally
Expand Down Expand Up @@ -571,7 +571,7 @@ function Test-TargetResource
if ($archiveEntryDestinationPath.EndsWith('\'))
{
$archiveEntryDestinationPath = $archiveEntryDestinationPath.TrimEnd('\')
if (-not (Test-Path -Path $archiveEntryDestinationPath -PathType Container))
if (-not (Test-Path -LiteralPath $archiveEntryDestinationPath -PathType Container))
{
Write-Verbose ($LocalizedData.DestMissingOrIncorrectTypeReason -f $archiveEntryDestinationPath)
$individualResult = $result = $false
Expand Down Expand Up @@ -749,7 +749,7 @@ function Get-CacheEntry
Write-Verbose -Message ($LocalizedData.UsingKeyToRetrieveHashValue -f $cacheEntryKey)

$cacheEntryPath = Join-Path -Path $script:cacheLocation -ChildPath $cacheEntryKey
if (-not (Test-Path -Path $cacheEntryPath))
if (-not (Test-Path -LiteralPath $cacheEntryPath))
{
Write-Verbose -Message ($LocalizedData.NoCacheValueFound)
}
Expand All @@ -758,7 +758,7 @@ function Get-CacheEntry
# ErrorAction seems to have no affect on this exception, (see: https://microsoft.visualstudio.com/web/wi.aspx?pcguid=cb55739e-4afe-46a3-970f-1b49d8ee7564&id=1185735)
try
{
$cacheEntry = Import-CliXml -Path $cacheEntryPath
$cacheEntry = Import-CliXml -LiteralPath $cacheEntryPath
Write-Verbose -Message ($LocalizedData.CacheValueFoundReturning -f $cacheEntry)
}
catch [System.Xml.XmlException]
Expand Down Expand Up @@ -805,12 +805,12 @@ function Set-CacheEntry
$cacheEntryPath = Join-Path -Path $script:cacheLocation -ChildPath $cacheEntryKey

Write-Verbose -Message ($LocalizedData.AboutToCacheValueInputObject -f $InputObject)
if (-not (Test-Path -Path $script:cacheLocation))
if (-not (Test-Path -LiteralPath $script:cacheLocation))
{
New-Item -Path $script:cacheLocation -ItemType Directory | Out-Null
}

Export-CliXml -Path $cacheEntryPath -InputObject $InputObject
Export-CliXml -LiteralPath $cacheEntryPath -InputObject $InputObject
}

<#
Expand All @@ -833,7 +833,7 @@ function Assert-PathArgumentValid

$ErrorActionPreference = 'Stop'

if (-not (Test-Path -Path $Path -PathType Leaf))
if (-not (Test-Path -LiteralPath $Path -PathType Leaf))
{
New-InvalidArgumentException -Message ($LocalizedData.InvalidSourcePath -f $Path) -ArgumentName 'Path'
}
Expand Down Expand Up @@ -1090,7 +1090,7 @@ function Mount-NetworkPath
$psDrive = $null

# Mount the drive only if not accessible
if (Test-Path -Path $Path -ErrorAction Ignore)
if (Test-Path -LiteralPath $Path -ErrorAction Ignore)
{
Write-Verbose -Message ($LocalizedData.PathPathIsAlreadyAccessiableNoMountNeeded -f $Path)
}
Expand Down Expand Up @@ -1169,7 +1169,7 @@ function New-Directory
if ($Force -and $PSCmdlet.ShouldProcess(($LocalizedData.RemoveFileAndRecreateAsDirectory -f $Path), $null, $null))
{
Write-Verbose -Message ($LocalizedData.RemovingDir -f $Path)
Remove-Item -Path $Path | Out-Null
Remove-Item -LiteralPath $Path | Out-Null
New-Item -Path $Path -ItemType Directory | Out-Null
}
else
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ None
* Fixes null verbose log output error. This resolves issue [#224](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/224).
* xDSCWebService
* Fixed issue where resource would fail to read redirection.config file. This resolves issue [#191] (https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/191)
* xArchive
* Fixed issue where resource would throw exception when file name contains brackets. This resolves issue [#255](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/255).

### 5.0.0.0

Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/MSFT_xArchive.TestHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function ConvertTo-FileStructure
{
$newFilePath = Join-Path -Path $ParentPath -ChildPath $key
New-Item -Path $newFilePath -ItemType File | Out-Null
Set-Content -Path $newFilePath -Value $ZipFileStructure[$key]
Set-Content -LiteralPath $newFilePath -Value $ZipFileStructure[$key]
}
else
{
Expand Down
15 changes: 14 additions & 1 deletion Tests/Unit/MSFT_xArchive.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ try
$testPathResult = Test-Path -Path "$destinationDirectoryPath\Folder1\Folder12\Folder13\Folder14"
$testPathResult | Should Be $false
}

It 'Should not remove an added file with Validate and any Checksum value specified'{
$zipFileName = 'ChecksumWithModifiedFile'
$fileToEditName = 'File1'
Expand Down Expand Up @@ -329,6 +329,19 @@ try
}

Context 'Test-TargetResource' {
It 'Should not throw when zip file contains wildcard characters' {
$zipFileName = 'ReturnCorrectValue['

$zipFileStructure = @{
Folder1 = @{
File1 = 'Fake file contents'
}
}

$zipFilePath = New-ZipFileFromHashtable -Name $zipFileName -ParentPath $script:currentTestDirectoryPath -ZipFileStructure $zipFileStructure

{ Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $script:currentTestDirectoryPath } | Should not throw
}
It 'Should return correct value based on presence or absence of an archive at the given location' {
$zipFileName = 'ReturnCorrectValue'

Expand Down

0 comments on commit e5a82a8

Please sign in to comment.