Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(decompress): '$ExtractDir' error with '.zip' and subdir #3472

Merged
merged 1 commit into from
May 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(decompress): '$ExtractDir' error with '.zip' and subdir
  • Loading branch information
niheaven committed May 17, 2019
commit ff972d2b01b29dae7e2bb829cc88e75e05247823
27 changes: 14 additions & 13 deletions lib/decompress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ function Expand-MsiArchive {
$Removal
)
$DestinationPath = $DestinationPath.TrimEnd("\")
if ($ExtractDir) {
$OriDestinationPath = $DestinationPath
$DestinationPath = "$DestinationPath\_tmp"
}
if ((get_config MSIEXTRACT_USE_LESSMSI)) {
$MsiPath = Get-HelperPath -Helper Lessmsi
$ArgList = @('x', "`"$Path`"", "`"$DestinationPath\\`"")
Expand All @@ -138,11 +142,11 @@ function Expand-MsiArchive {
abort "Failed to extract files from $Path.`nLog file:`n $(friendly_path $LogPath)`n$(new_issue_msg $app $bucket 'decompress error')"
}
if ($ExtractDir -and (Test-Path "$DestinationPath\SourceDir")) {
movedir "$DestinationPath\SourceDir\$ExtractDir" $DestinationPath | Out-Null
Remove-Item "$DestinationPath\SourceDir" -Recurse -Force
movedir "$DestinationPath\SourceDir\$ExtractDir" $OriDestinationPath | Out-Null
Remove-Item $DestinationPath -Recurse -Force
} elseif ($ExtractDir) {
Get-ChildItem $DestinationPath -Exclude $ExtractDir, $Path | Remove-Item -Recurse -Force
movedir "$DestinationPath\$ExtractDir" $DestinationPath | Out-Null
movedir "$DestinationPath\$ExtractDir" $OriDestinationPath | Out-Null
Remove-Item $DestinationPath -Recurse -Force
} elseif (Test-Path "$DestinationPath\SourceDir") {
movedir "$DestinationPath\SourceDir" $DestinationPath | Out-Null
}
Expand Down Expand Up @@ -207,6 +211,10 @@ function Expand-ZipArchive {
[Switch]
$Removal
)
if ($ExtractDir) {
$OriDestinationPath = $DestinationPath
$DestinationPath = "$DestinationPath\_tmp"
}
# All methods to unzip the file require .NET4.5+
if ($PSVersionTable.PSVersion.Major -lt 5) {
Add-Type -AssemblyName System.IO.Compression.FileSystem
Expand Down Expand Up @@ -236,8 +244,8 @@ function Expand-ZipArchive {
Microsoft.PowerShell.Archive\Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force
}
if ($ExtractDir) {
Get-ChildItem $DestinationPath -Exclude $ExtractDir, $Path | Remove-Item -Recurse -Force
movedir "$DestinationPath\$ExtractDir" $DestinationPath | Out-Null
movedir "$DestinationPath\$ExtractDir" $OriDestinationPath | Out-Null
Remove-Item $DestinationPath -Recurse -Force
}
if ($Removal) {
# Remove original archive file
Expand All @@ -254,15 +262,12 @@ function Expand-DarkArchive {
[Parameter(Position = 1)]
[String]
$DestinationPath = (Split-Path $Path),
[String]
$ExtractDir,
[Parameter(ValueFromRemainingArguments = $true)]
[String]
$Switches,
[Switch]
$Removal
)
$DestinationPath = $DestinationPath.TrimEnd("\")
$LogPath = "$(Split-Path $Path)\dark.log"
$ArgList = @('-nologo', "-x `"$DestinationPath`"", "`"$Path`"")
if ($Switches) {
Expand All @@ -275,10 +280,6 @@ function Expand-DarkArchive {
if (Test-Path $LogPath) {
Remove-Item $LogPath -Force
}
if ($ExtractDir) {
Get-ChildItem $DestinationPath -Exclude $ExtractDir, $Path | Remove-Item -Recurse -Force
movedir "$DestinationPath\$ExtractDir" $DestinationPath | Out-Null
}
if ($Removal) {
# Remove original archive file
Remove-Item $Path -Force
Expand Down