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

ExtractFiles can overwrite destination folder #11594

Closed
wants to merge 9 commits into from
15 changes: 14 additions & 1 deletion Tasks/ExtractFilesV1/extractfilestask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ var cleanDestinationFolder: boolean = tl.getBoolInput('cleanDestinationFolder',
var repoRoot: string = tl.getVariable('System.DefaultWorkingDirectory');
tl.debug('repoRoot: ' + repoRoot);

var preventFileOverwriteVar: string = tl.getVariable('EXTRACT_FILES_PREVENT_FILE_OVERWRITE');
var preventFileOverwrite: boolean = !!preventFileOverwriteVar && preventFileOverwriteVar.toLowerCase() === 'true';

var win = tl.osType().match(/^Win/);
tl.debug('win: ' + win);

Expand Down Expand Up @@ -190,6 +193,9 @@ function unzipExtract(file, destinationFolder) {
xpUnzipLocation = tl.which('unzip', true);
}
var unzip = tl.tool(xpUnzipLocation);
if (!preventFileOverwrite) {
unzip.arg('-o');
}
unzip.arg(file);
unzip.arg('-d');
unzip.arg(destinationFolder);
Expand All @@ -200,6 +206,9 @@ function sevenZipExtract(file, destinationFolder) {
console.log(tl.loc('SevenZipExtractFile', file));
var sevenZip = tl.tool(getSevenZipLocation());
sevenZip.arg('x');
if (!preventFileOverwrite) {
sevenZip.arg('-aoa');
}
sevenZip.arg('-o' + destinationFolder);
sevenZip.arg(file);
return handleExecResult(sevenZip.execSync(), file);
Expand All @@ -211,7 +220,11 @@ function tarExtract(file, destinationFolder) {
xpTarLocation = tl.which('tar', true);
}
var tar = tl.tool(xpTarLocation);
tar.arg('-xvf'); // tar will correctly handle compression types outlined in isTar()
tar.arg('-xv'); // tar will correctly handle compression types outlined in isTar()
if (preventFileOverwrite) {
tar.arg('-k');
}
tar.arg('-f');
tar.arg(file);
tar.arg('-C');
tar.arg(destinationFolder);
Expand Down
8 changes: 4 additions & 4 deletions Tests-Legacy/L0/ExtractFiles/extractFilesLinux.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"output": true
},
"exec": {
"/usr/bin/unzip mockedBuildSources/foo.zip -d output": {
"/usr/bin/unzip -o mockedBuildSources/foo.zip -d output": {
"code": 0,
"stdout": "extracted mockedBuildSources/foo.zip",
"stderr": ""
Expand All @@ -60,17 +60,17 @@
"stdout": "extracted mockedBuildSources/foo.tar.gz",
"stderr": ""
},
"/usr/bin/unzip mockedBuildSources/subdir/foo.jar -d output": {
"/usr/bin/unzip -o mockedBuildSources/subdir/foo.jar -d output": {
"code": 0,
"stdout": "extracted mockedBuildSources/subdir/foo.jar",
"stderr": ""
},
"/usr/bin/7z x -ooutput mockedBuildSources/subdir/subdir/foo.7z": {
"/usr/bin/7z x -aoa -ooutput mockedBuildSources/subdir/subdir/foo.7z": {
"code": 0,
"stdout": "extracted mockedBuildSources/subdir/subdir/foo.7z",
"stderr": ""
},
"/usr/bin/unzip mockedBuildSources/subdir/foo.zip -d output": {
"/usr/bin/unzip -o mockedBuildSources/subdir/foo.zip -d output": {
"code": 0,
"stdout": "extracted mockedBuildSources/subdir/foo.zip",
"stderr": ""
Expand Down
16 changes: 8 additions & 8 deletions Tests-Legacy/L0/ExtractFiles/extractFilesWin.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,42 @@
"output": true
},
"exec": {
"/ExtractFiles/7zip/7z.exe x -ooutput mockedBuildSources/foo.zip": {
"/ExtractFiles/7zip/7z.exe x -aoa -ooutput mockedBuildSources/foo.zip": {
"code": 0,
"stdout": "extracted mockedBuildSources/foo.zip",
"stderr": ""
},
"/ExtractFiles/7zip/7z.exe x -ooutput mockedBuildSources/foo.tar": {
"/ExtractFiles/7zip/7z.exe x -aoa -ooutput mockedBuildSources/foo.tar": {
"code": 0,
"stdout": "extracted mockedBuildSources/foo.tar",
"stderr": ""
},
"/ExtractFiles/7zip/7z.exe x -ooutput/_foo.tar.gz_ mockedBuildSources/foo.tar.gz": {
"/ExtractFiles/7zip/7z.exe x -aoa -ooutput/_foo.tar.gz_ mockedBuildSources/foo.tar.gz": {
"code": 0,
"stdout": "extracted mockedBuildSources/foo.tar.gz",
"stderr": ""
},
"/ExtractFiles/7zip/7z.exe x -ooutput output/_foo.tar.gz_/foo.tar": {
"/ExtractFiles/7zip/7z.exe x -aoa -ooutput output/_foo.tar.gz_/foo.tar": {
"code": 0,
"stdout": "extracted output/_foo.tar.gz_/foo.tar",
"stderr": ""
},
"/ExtractFiles/7zip/7z.exe x -ooutput/ output/_foo.tar.gz_/foo.tar": {
"/ExtractFiles/7zip/7z.exe x -aoa -ooutput/ output/_foo.tar.gz_/foo.tar": {
"code": 0,
"stdout": "extractedoutput/_foo.tar.gz_/foo.tar",
"stderr": ""
},
"/ExtractFiles/7zip/7z.exe x -ooutput mockedBuildSources/subdir/foo.jar": {
"/ExtractFiles/7zip/7z.exe x -aoa -ooutput mockedBuildSources/subdir/foo.jar": {
"code": 0,
"stdout": "extracted mockedBuildSources/subdir/foo.jar",
"stderr": ""
},
"/ExtractFiles/7zip/7z.exe x -ooutput mockedBuildSources/subdir/subdir/foo.7z": {
"/ExtractFiles/7zip/7z.exe x -aoa -ooutput mockedBuildSources/subdir/subdir/foo.7z": {
"code": 0,
"stdout": "extracted mockedBuildSources/subdir/subdir/foo.7z",
"stderr": ""
},
"/ExtractFiles/7zip/7z.exe x -ooutput mockedBuildSources/subdir/foo.zip": {
"/ExtractFiles/7zip/7z.exe x -aoa -ooutput mockedBuildSources/subdir/foo.zip": {
"code": 0,
"stdout": "extracted mockedBuildSources/subdir/foo.zip",
"stderr": ""
Expand Down