Skip to content

Commit 426ba81

Browse files
authored
Merge pull request #153 from EzzhevNikita/users/EzzhevNikita/add-ability-to-overwrite-while-extraction
Add option to overwrite files in target for extract7z function
2 parents 5dbfaf3 + aeb2d4f commit 426ba81

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

Invoke-7zdec.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ param(
44
[string]$Source,
55

66
[Parameter(Mandatory = $true)]
7-
[string]$Target)
7+
[string]$Target,
8+
9+
[Parameter(Mandatory = $false)]
10+
[boolean]$OverrideDestDirectory)
811

912
# This script translates the output from 7zdec into UTF8. Node has limited
1013
# built-in support for encodings.
@@ -35,8 +38,9 @@ $writer = New-Object System.IO.StreamWriter($stdout, $utf8)
3538
Set-Location -LiteralPath $Target
3639

3740
# Print the ##command.
41+
$overrideDest = $(If ($OverrideDestDirectory) { "-aoa" } Else { "" })
3842
$_7zdec = Join-Path -Path "$PSScriptRoot" -ChildPath "externals/7zdec.exe"
39-
[System.Console]::WriteLine("##[command]$_7zdec x `"$Source`"")
43+
[System.Console]::WriteLine("##[command]$_7zdec $overrideDest x `"$Source`"")
4044

4145
# The $OutputEncoding variable instructs PowerShell how to interpret the output
4246
# from the external command.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azure-pipelines-tool-lib",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Azure Pipelines Tool Installer Lib for CI/CD Tasks",
55
"main": "tool.js",
66
"scripts": {

tool.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,10 @@ export async function cacheFile(sourceFile: string,
382382
* time of this writing, it is freely available from the LZMA SDK that is available on the 7zip website.
383383
* Be sure to check the current license agreement. If 7zr.exe is bundled with your task, then the path
384384
* to 7zr.exe can be pass to this function.
385+
* @param overwriteDest Overwrite files in destination catalog. Optional.
385386
* @returns path to the destination directory
386387
*/
387-
export async function extract7z(file: string, dest?: string, _7zPath?: string): Promise<string> {
388+
export async function extract7z(file: string, dest?: string, _7zPath?: string, overwriteDest?: boolean): Promise<string> {
388389
if (process.platform != 'win32') {
389390
throw new Error('extract7z() not supported on current OS');
390391
}
@@ -402,20 +403,25 @@ export async function extract7z(file: string, dest?: string, _7zPath?: string):
402403

403404
if (_7zPath) {
404405
// extract
405-
let _7z: trm.ToolRunner = tl.tool(_7zPath)
406-
.arg('x') // eXtract files with full paths
407-
.arg('-bb1') // -bb[0-3] : set output log level
408-
.arg('-bd') // disable progress indicator
409-
.arg('-sccUTF-8') // set charset for for console input/output
410-
.arg(file);
406+
const _7z: trm.ToolRunner = tl.tool(_7zPath);
407+
if (overwriteDest) {
408+
_7z.arg('-aoa');
409+
}
410+
411+
_7z.arg('x') // eXtract files with full paths
412+
.arg('-bb1') // -bb[0-3] : set output log level
413+
.arg('-bd') // disable progress indicator
414+
.arg('-sccUTF-8') // set charset for for console input/output
415+
.arg(file);
411416
await _7z.exec();
412417
}
413418
else {
414419
// extract
415420
let escapedScript = path.join(__dirname, 'Invoke-7zdec.ps1').replace(/'/g, "''").replace(/"|\n|\r/g, ''); // double-up single quotes, remove double quotes and newlines
416421
let escapedFile = file.replace(/'/g, "''").replace(/"|\n|\r/g, '');
417422
let escapedTarget = dest.replace(/'/g, "''").replace(/"|\n|\r/g, '');
418-
let command: string = `& '${escapedScript}' -Source '${escapedFile}' -Target '${escapedTarget}'`
423+
const overrideDestDirectory: number = overwriteDest ? 1 : 0;
424+
const command: string = `& '${escapedScript}' -Source '${escapedFile}' -Target '${escapedTarget}' -OverrideDestDirectory ${overrideDestDirectory}`;
419425
let powershellPath = tl.which('powershell', true);
420426
let powershell: trm.ToolRunner = tl.tool(powershellPath)
421427
.line('-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command')

0 commit comments

Comments
 (0)