diff --git a/Invoke-7zdec.ps1 b/Invoke-7zdec.ps1 index 8b39bb4..5a295b0 100644 --- a/Invoke-7zdec.ps1 +++ b/Invoke-7zdec.ps1 @@ -4,7 +4,10 @@ param( [string]$Source, [Parameter(Mandatory = $true)] - [string]$Target) + [string]$Target, + + [Parameter(Mandatory = $false)] + [boolean]$OverrideDestDirectory) # This script translates the output from 7zdec into UTF8. Node has limited # built-in support for encodings. @@ -35,8 +38,9 @@ $writer = New-Object System.IO.StreamWriter($stdout, $utf8) Set-Location -LiteralPath $Target # Print the ##command. +$overrideDest = $(If ($OverrideDestDirectory) { "-aoa" } Else { "" }) $_7zdec = Join-Path -Path "$PSScriptRoot" -ChildPath "externals/7zdec.exe" -[System.Console]::WriteLine("##[command]$_7zdec x `"$Source`"") +[System.Console]::WriteLine("##[command]$_7zdec $overrideDest x `"$Source`"") # The $OutputEncoding variable instructs PowerShell how to interpret the output # from the external command. diff --git a/package-lock.json b/package-lock.json index 3d53cd3..12ae500 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "azure-pipelines-tool-lib", - "version": "1.2.0", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9a33321..c8351fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "azure-pipelines-tool-lib", - "version": "1.2.0", + "version": "1.3.0", "description": "Azure Pipelines Tool Installer Lib for CI/CD Tasks", "main": "tool.js", "scripts": { diff --git a/tool.ts b/tool.ts index 1923d36..2a6f872 100644 --- a/tool.ts +++ b/tool.ts @@ -382,9 +382,10 @@ export async function cacheFile(sourceFile: string, * time of this writing, it is freely available from the LZMA SDK that is available on the 7zip website. * Be sure to check the current license agreement. If 7zr.exe is bundled with your task, then the path * to 7zr.exe can be pass to this function. + * @param overwriteDest Overwrite files in destination catalog. Optional. * @returns path to the destination directory */ -export async function extract7z(file: string, dest?: string, _7zPath?: string): Promise { +export async function extract7z(file: string, dest?: string, _7zPath?: string, overwriteDest?: boolean): Promise { if (process.platform != 'win32') { throw new Error('extract7z() not supported on current OS'); } @@ -402,12 +403,16 @@ export async function extract7z(file: string, dest?: string, _7zPath?: string): if (_7zPath) { // extract - let _7z: trm.ToolRunner = tl.tool(_7zPath) - .arg('x') // eXtract files with full paths - .arg('-bb1') // -bb[0-3] : set output log level - .arg('-bd') // disable progress indicator - .arg('-sccUTF-8') // set charset for for console input/output - .arg(file); + const _7z: trm.ToolRunner = tl.tool(_7zPath); + if (overwriteDest) { + _7z.arg('-aoa'); + } + + _7z.arg('x') // eXtract files with full paths + .arg('-bb1') // -bb[0-3] : set output log level + .arg('-bd') // disable progress indicator + .arg('-sccUTF-8') // set charset for for console input/output + .arg(file); await _7z.exec(); } else { @@ -415,7 +420,8 @@ export async function extract7z(file: string, dest?: string, _7zPath?: string): let escapedScript = path.join(__dirname, 'Invoke-7zdec.ps1').replace(/'/g, "''").replace(/"|\n|\r/g, ''); // double-up single quotes, remove double quotes and newlines let escapedFile = file.replace(/'/g, "''").replace(/"|\n|\r/g, ''); let escapedTarget = dest.replace(/'/g, "''").replace(/"|\n|\r/g, ''); - let command: string = `& '${escapedScript}' -Source '${escapedFile}' -Target '${escapedTarget}'` + const overrideDestDirectory: number = overwriteDest ? 1 : 0; + const command: string = `& '${escapedScript}' -Source '${escapedFile}' -Target '${escapedTarget}' -OverrideDestDirectory ${overrideDestDirectory}`; let powershellPath = tl.which('powershell', true); let powershell: trm.ToolRunner = tl.tool(powershellPath) .line('-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command')