Skip to content

Commit a8c8616

Browse files
Anatoly BolshakovAlexander Smolyakov
andauthored
[ArchiveFilesV2] Fixed 'The system cannot find the file specified' error when root folder is parent for archive target path (#15912) (#15926)
* Fixed issue with remove archive/scan files order * Added L0 tests * Tests - added dummy file to root directory * Update Tasks/ArchiveFilesV2/archivefiles.ts - formatting Co-authored-by: Alexander Smolyakov <[email protected]> * Update Tasks/ArchiveFilesV2/archivefiles.ts Co-authored-by: Alexander Smolyakov <[email protected]> * Update Tasks/ArchiveFilesV2/archivefiles.ts Co-authored-by: Alexander Smolyakov <[email protected]> Co-authored-by: Alexander Smolyakov <[email protected]> Co-authored-by: Alexander Smolyakov <[email protected]>
1 parent ff8df70 commit a8c8616

File tree

7 files changed

+123
-74
lines changed

7 files changed

+123
-74
lines changed

Tasks/ArchiveFilesV2/Tests/L0.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ describe('ArchiveFiles L0 Suite', function () {
2828
if (!fs.existsSync(testOutput)) {
2929
fs.mkdirSync(testOutput);
3030
}
31+
32+
const replaceTestOutput = path.join(__dirname, 'test_output', 'replace_test');
33+
if (!fs.existsSync(replaceTestOutput)) {
34+
fs.mkdirSync(replaceTestOutput);
35+
}
3136
})
3237

3338
const files = (n) => {
@@ -139,5 +144,36 @@ if (process.platform.indexOf('darwin') < 0) {
139144
assert(fs.existsSync(expectedArchivePath), `Should have successfully created the archive at ${expectedArchivePath}, instead directory contents are ${fs.readdirSync(path.dirname(expectedArchivePath))}`);
140145
}, tr, done);
141146
});
147+
148+
it('Replace archive file in the root folder', function(done: Mocha.Done) {
149+
const archiveName = "archive.zip";
150+
const replaceTestDir = path.join(__dirname, 'test_output', 'replace_test');
151+
const archivePath = path.join(replaceTestDir, archiveName);
152+
this.timeout(5000);
153+
process.env['archiveType'] = 'zip';
154+
process.env['archiveFile'] = archiveName;
155+
process.env['includeRootFolder'] = 'false';
156+
process.env['rootFolderOrFile'] = replaceTestDir;
157+
158+
fs.writeFileSync(path.join(replaceTestDir, 'test_file.txt'), 'test data');
159+
160+
fs.copyFileSync(
161+
path.join(__dirname, 'resources', archiveName),
162+
path.join(archivePath)
163+
);
164+
165+
let expectedArchivePath = archivePath;
166+
167+
let tp: string = path.join(__dirname, 'L0ReplaceArchiveInRootFolder.js');
168+
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
169+
170+
tr.run();
171+
console.info(tr.stdout);
172+
runValidations(() => {
173+
assert(tr.succeeded, "Task should succeed");
174+
assert(tr.stdout.indexOf('Creating archive') > -1, 'Should have tried to create archive');
175+
assert(fs.existsSync(expectedArchivePath), `Should have successfully created the archive at ${expectedArchivePath}, instead directory contents are ${fs.readdirSync(path.dirname(expectedArchivePath))}`);
176+
}, tr, done);
177+
});
142178
}
143179
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import tmrm = require('azure-pipelines-task-lib/mock-run');
2+
import path = require('path');
3+
4+
let taskPath = path.join(__dirname, '..', 'archivefiles.js');
5+
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
6+
7+
process.env['AGENT_TEMPDIRECTORY'] = path.join(__dirname, 'test_temp');
8+
9+
tmr.setInput('rootFolderOrFile', path.join(__dirname, 'test_output', 'replace_test'));
10+
tmr.setInput('includeRootFolder', process.env['includeRootFolder']);
11+
tmr.setInput('archiveType', process.env['archiveType']);
12+
tmr.setInput('archiveFile', path.join(__dirname, 'test_output', 'replace_test', process.env['archiveFile']));
13+
tmr.setInput('replaceExistingArchive', 'true');
14+
tmr.setInput('tarCompression', 'gz');
15+
16+
tmr.run(true);
22 Bytes
Binary file not shown.

Tasks/ArchiveFilesV2/archivefiles.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,6 @@ function createArchive(files: string[]) {
320320
function doWork() {
321321
try {
322322
tl.setResourcePath(path.join( __dirname, 'task.json'));
323-
// Find matching archive files
324-
var files: string[] = findFiles();
325-
utils.reportArchivePlan(files).forEach(function(line) {
326-
console.log(line);
327-
});
328-
329-
tl.debug('Listing all ' + files.length + ' files to archive:');
330-
for (var i = 0; i < files.length; i++) {
331-
tl.debug(files[i]);
332-
}
333323

334324
// replaceExistingArchive before creation?
335325
if (tl.exist(archiveFile)) {
@@ -350,6 +340,13 @@ function doWork() {
350340
}
351341
}
352342

343+
// Find matching archive files
344+
var files: string[] = findFiles();
345+
utils.reportArchivePlan(files).forEach(line => console.log(line));
346+
347+
tl.debug(`Listing all ${files.length} files to archive:`);
348+
files.forEach(file => tl.debug(file));
349+
353350
//ensure output folder exists
354351
var destinationFolder = path.dirname(archiveFile);
355352
tl.debug("Checking for archive destination folder:" + destinationFolder);

Tasks/ArchiveFilesV2/package-lock.json

Lines changed: 62 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)