|
186 | 186 | Invoke-Main $NICS_INFO $IPS_INFO |
187 | 187 | """ # noqa |
188 | 188 |
|
| 189 | +EXTRACT_TEMPLATE = """ |
| 190 | +function Extract-Path { |
| 191 | + [CmdletBinding()] |
| 192 | + Param( |
| 193 | + [Parameter(Mandatory=$true)] |
| 194 | + [String]$source, |
| 195 | +
|
| 196 | + [Parameter(Mandatory=$true)] |
| 197 | + [String]$destination |
| 198 | + ) |
| 199 | + try { |
| 200 | + [Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | Out-Null |
| 201 | + $zip = [System.IO.Compression.ZipFile]::OpenRead($source) |
| 202 | + foreach ($entry in $zip.Entries) { |
| 203 | + $targetPath = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($destination, $entry.FullName)) |
| 204 | + if ($entry.FullName -match '[\\/]$') { |
| 205 | + if (!(Test-Path $targetPath)) { New-Item -ItemType Directory -Force -Path $targetPath | Out-Null } |
| 206 | + } else { |
| 207 | + $parentPath = Split-Path $targetPath |
| 208 | + if (!(Test-Path $parentPath)) { New-Item -ItemType Directory -Force -Path $parentPath | Out-Null } |
| 209 | + [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $targetPath, $true) |
| 210 | + } |
| 211 | + } |
| 212 | + } finally { |
| 213 | + if ($zip) { $zip.Dispose() } |
| 214 | + } |
| 215 | +} |
| 216 | +Extract-Path '%(source)s' '%(destination)s' |
| 217 | +""" # noqa |
| 218 | + |
189 | 219 |
|
190 | 220 | class BaseWindowsMorphingTools(base.BaseOSMorphingTools): |
191 | 221 |
|
@@ -303,16 +333,7 @@ def _expand_archive(self, path, destination, overwrite=True): |
303 | 333 | "rm -recurse -force %s" % destination) |
304 | 334 |
|
305 | 335 | self._conn.exec_ps_command( |
306 | | - "if(([System.Management.Automation.PSTypeName]" |
307 | | - "'System.IO.Compression.ZipFile').Type -or " |
308 | | - "[System.Reflection.Assembly]::LoadWithPartialName(" |
309 | | - "'System.IO.Compression.FileSystem')) {" |
310 | | - "[System.IO.Compression.ZipFile]::ExtractToDirectory('%(path)s', " |
311 | | - "'%(destination)s')} else {mkdir -Force '%(destination)s'; " |
312 | | - "$shell = New-Object -ComObject Shell.Application;" |
313 | | - "$shell.Namespace('%(destination)s').copyhere(($shell.NameSpace(" |
314 | | - "'%(path)s')).items())}" % |
315 | | - {"path": path, "destination": destination}, |
| 336 | + EXTRACT_TEMPLATE % {"source": path, "destination": destination}, |
316 | 337 | ignore_stdout=True) |
317 | 338 |
|
318 | 339 | def _set_service_start_mode(self, key_name, service_name, start_mode): |
|
0 commit comments