Skip to content

Commit

Permalink
(#1332) Add switch to disable logging for archive extraction
Browse files Browse the repository at this point in the history
Adds a switch "disableLogging" to Get-ChocolateyUnzip and
Install-ChocolateyZipPackage. This switch disable 7zip logging of
extracted filenames and does not write out the log of extracted
files. Install-ChocolateyZip passes the switch to Get-ChocolateyUnzip,
and the functionality is implemented into Get-ChocolateyUnzip.

This is useful for large archives with a very large number of files as
logging the extracted files can significantly slow down the extraction
process.
  • Loading branch information
TheCakeIsNaOH committed Jun 30, 2022
1 parent d8ca7ba commit d9b7be2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ folder and its contents will be extracted to the destination.
OPTIONAL - This will facilitate logging unzip activity for subsequent
uninstalls
.PARAMETER DisableLogging
OPTIONAL - This disables logging of the extracted items. It speeds up
extraction of archives with many files.
Usage of this parameter will prevent Uninstall-ChocolateyZipPackage
from working, extracted files will have to be cleaned up with
Remove-Item or a similar command instead.
.PARAMETER IgnoredArguments
Allows splatting with arguments that do not apply. Do not use directly.
Expand All @@ -93,6 +101,7 @@ param(
[parameter(Mandatory=$false, Position=2)][string] $specificFolder,
[parameter(Mandatory=$false, Position=3)][string] $packageName,
[alias("file64")][parameter(Mandatory=$false)][string] $fileFullPath64,
[parameter(Mandatory=$false)][switch] $disableLogging,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)

Expand Down Expand Up @@ -156,7 +165,12 @@ param(
}
$workingDirectory = $workingDirectory.ProviderPath

$params = "x -aoa -bd -bb1 -o`"$destinationNoRedirection`" -y `"$fileFullPathNoRedirection`""
$loggingParam = '-bb1'
if ($disableLogging) {
$loggingParam = '-bb0'
}

$params = "x -aoa -bd $loggingParam -o`"$destinationNoRedirection`" -y `"$fileFullPathNoRedirection`""
if ($specificfolder) {
$params += " `"$specificfolder`""
}
Expand Down Expand Up @@ -219,7 +233,7 @@ param(
Set-PowerShellExitCode $exitCode
Write-Debug "Command ['$7zip' $params] exited with `'$exitCode`'."

if ($zipExtractLogFullPath) {
if ($zipExtractLogFullPath -and -not $disableLogging) {
Set-Content $zipExtractLogFullPath $global:zipFileList.ToString() -Encoding UTF8 -Force
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ Will be used for Url64bit if Url64bit is empty. Available in 0.10.7+.
This parameter provides compatibility, but should not be used directly
and not with the community package repository until January 2018.
.PARAMETER DisableLogging
OPTIONAL - This disables logging of the extracted items. It speeds up
extraction of archives with many files.
Usage of this parameter will prevent Uninstall-ChocolateyZipPackage
from working, extracted files will have to be cleaned up with
Remove-Item or a similar command instead.
.PARAMETER IgnoredArguments
Allows splatting with arguments that do not apply. Do not use directly.
Expand Down Expand Up @@ -191,6 +199,7 @@ param(
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}},
[alias("fileFullPath")][parameter(Mandatory=$false)][string] $file = '',
[alias("fileFullPath64")][parameter(Mandatory=$false)][string] $file64 = '',
[parameter(Mandatory=$false)][switch] $disableLogging,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)

Expand All @@ -213,5 +222,5 @@ param(
}

$filePath = Get-ChocolateyWebFile $packageName $downloadFilePath $url $url64bit -checkSum $checkSum -checksumType $checksumType -checkSum64 $checkSum64 -checksumType64 $checksumType64 -options $options -getOriginalFileName
Get-ChocolateyUnzip "$filePath" $unzipLocation $specificFolder $packageName
Get-ChocolateyUnzip "$filePath" $unzipLocation $specificFolder $packageName -disableLogging:$disableLogging
}

0 comments on commit d9b7be2

Please sign in to comment.