Skip to content

Commit

Permalink
Change Compress archive to WMF4 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Horacio Fernandez committed May 15, 2015
1 parent b843f46 commit cd28c47
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions DSCResources/RS_rsModuleZipSum/RS_rsModuleZipSum.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,68 @@ Function Set-TargetResource {
if(!(Test-Path -Path $(Join-Path $destination -ChildPath $($moduleName, '.zip' -join ''))) -or !($((Get-FileHash -Path $(Join-Path $destination -ChildPath $($moduleName, '.zip' -join '')) -ErrorAction SilentlyContinue).Hash) -eq $(Get-Content -Path $(Join-Path $destination -ChildPath $($moduleName, '.zip.checksum' -join '')) -ErrorAction SilentlyContinue))) {
Remove-Item -Path $((Join-Path $destination -ChildPath $module), '*' -join '') -Force
if($module -ne "PowerShellAccessControl") {
Compress-Archive -Path $(Join-Path $modulePath -ChildPath $module) -DestinationPath $((Join-Path $destination -ChildPath $moduleName), '.zip' -join '') -ErrorAction SilentlyContinue
New-ResourceZip -modulePath $(Join-Path $modulePath -ChildPath $module) -outputDir $destination
}
}
}
}
}
New-DSCCheckSum -ConfigurationPath 'C:\Program Files\WindowsPowerShell\DscService\Modules' -Force
}

Function New-ResourceZip
{
param
(
$modulePath,
$outputDir
)
#Read the module name & version
$module = Import-Module $modulePath -PassThru
$moduleName = $module.Name
$version = $module.Version.ToString()
Remove-Module $moduleName

$zipFilename = ("{0}_{1}.zip" -f $moduleName, $version)
$outputPath = Join-Path $outputDir $zipFilename
if ( -not (Test-Path $outputPath) )
{
# Code to create an 'acceptable' structured ZIP file for DSC
# Courtesy of: @Neptune443 (http://blog.cosmoskey.com/powershell/desired-state-configuration-in-pull-mode-over-smb/)
[byte[]]$data = New-Object byte[] 22
$data[0] = 80
$data[1] = 75
$data[2] = 5
$data[3] = 6
[System.IO.File]::WriteAllBytes($outputPath, $data)
$acl = Get-Acl -Path $outputPath

$shellObj = New-Object -ComObject "Shell.Application"
$zipFileObj = $shellObj.NameSpace($outputPath)
if ($zipFileObj -ne $null)
{
$target = get-item $modulePath
# CopyHere might be async and we might need to wait for the Zip file to have been created full before we continue
# Added flags to minimize any UI & prompts etc.
$zipFileObj.CopyHere($target.FullName, 0x14)
do
{
$zipCount = $zipFileObj.Items().count
Start-sleep -Milliseconds 50
}
While ($zipFileObj.Items().count -lt 1)
[Runtime.InteropServices.Marshal]::ReleaseComObject($zipFileObj) | Out-Null
Set-Acl -Path $outputPath -AclObject $acl
}
else
{
Throw "Failed to create the zip file"
}
}
else
{
$outputPath = $null
}

return $outputPath
}
Export-ModuleMember -Function *-TargetResource

0 comments on commit cd28c47

Please sign in to comment.