Skip to content
Permalink
Browse files

Remove fallbacks for Expand-Archive (#5731)

  • Loading branch information...
niphlod authored and potatoqualitee committed Jun 12, 2019
1 parent cefade7 commit 8fa19e6fbab61d4dae3500f9027a11adb19e4ba3
Showing with 21 additions and 29 deletions.
  1. +5 −14 functions/Install-DbaSqlWatch.ps1
  2. +5 −15 functions/Install-DbaWhoIsActive.ps1
  3. +11 −0 tests/dbatools.Tests.ps1
@@ -155,20 +155,11 @@ function Install-DbaSqlWatch {
$LocalCacheFolder = Split-Path $LocallyCachedZip -Parent

Write-Message -Level Verbose "Extracting $LocallyCachedZip to $LocalCacheFolder"
if (Get-Command -ErrorAction SilentlyContinue -Name "Expand-Archive") {
try {
Expand-Archive -Path $LocallyCachedZip -DestinationPath $LocalCacheFolder -Force
} catch {
Stop-Function -Message "Unable to extract $LocallyCachedZip. Archive may not be valid." -ErrorRecord $_
return
}
} else {
# Keep it backwards compatible
$shell = New-Object -ComObject Shell.Application
$zipPackage = $shell.NameSpace($LocallyCachedZip)
$destinationFolder = $shell.NameSpace($LocalCacheFolder)
Get-ChildItem "$LocalCacheFolder\SqlWatch.zip" | Remove-Item
$destinationFolder.CopyHere($zipPackage.Items())
try {
Expand-Archive -Path $LocallyCachedZip -DestinationPath $LocalCacheFolder -Force
} catch {
Stop-Function -Message "Unable to extract $LocallyCachedZip. Archive may not be valid." -ErrorRecord $_
return
}

Write-Message -Level VeryVerbose "Deleting $LocallyCachedZip"
@@ -134,21 +134,11 @@ function Install-DbaWhoIsActive {
if ($PSCmdlet.ShouldProcess($env:computername, "Unpacking zipfile")) {

Unblock-File $zipfile -ErrorAction SilentlyContinue

if (Get-Command -ErrorAction SilentlyContinue -Name "Expand-Archive") {
try {
Expand-Archive -Path $zipfile -DestinationPath $temp -Force
} catch {
Stop-Function -Message "Unable to extract $zipfile. Archive may not be valid." -ErrorRecord $_
return
}
} else {
# Keep it backwards compatible
$shell = New-Object -ComObject Shell.Application
$zipPackage = $shell.NameSpace($zipfile)
$destinationFolder = $shell.NameSpace($temp)
Get-ChildItem "$temp\who*active*.sql" | Remove-Item
$destinationFolder.CopyHere($zipPackage.Items())
try {
Expand-Archive -Path $zipfile -DestinationPath $temp -Force
} catch {
Stop-Function -Message "Unable to extract $zipfile. Archive may not be valid." -ErrorRecord $_
return
}
Remove-Item -Path $zipfile
}
@@ -118,6 +118,17 @@ Describe "$ModuleName style" -Tag 'Compliance' {
}
}
}
Context "Shell.Application" {
# Not every PS instance has Shell.Application
foreach ($f in $AllPublicFunctions) {
$NotAllowed = Select-String -Path $f -Pattern 'shell.application'
if ($NotAllowed.Count -gt 0) {
It "$f should not use Shell.Application (usually fallbacks for Expand-Archive, which dbatools ships), see #4800" {
$NotAllowed.Count | Should -Be 0
}
}
}
}

}

0 comments on commit 8fa19e6

Please sign in to comment.
You can’t perform that action at this time.