Skip to content

Commit d5793b9

Browse files
authored
Revert "Rollback CopyFilesV2 (#16715)" (#16775)
This reverts commit 12f2f1f.
1 parent 12f2f1f commit d5793b9

16 files changed

+332
-100
lines changed

Tasks/CopyFilesV2/Tests/L0FailsIfThereIsMkdirError.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,33 @@ answers.find[path.normalize('/srcDir')] = [
2323
path.normalize('/srcDir/someOtherDir/file2.file'),
2424
];
2525
runner.setAnswers(answers);
26-
runner.registerMockExport('stats', (itemPath: string) => {
27-
console.log('##vso[task.debug]stats ' + itemPath);
26+
27+
fs.existsSync = (itemPath: string) => {
2828
switch (itemPath) {
2929
case path.normalize('/srcDir/someOtherDir'):
30-
return { isDirectory: () => true };
3130
case path.normalize('/srcDir/someOtherDir/file1.file'):
3231
case path.normalize('/srcDir/someOtherDir/file2.file'):
33-
return { isDirectory: () => false };
32+
return true;
33+
default:
34+
return false;
35+
}
36+
}
37+
38+
fs.statSync = (itemPath: string) => {
39+
const itemStats: fs.Stats = new fs.Stats();
40+
switch (itemPath) {
41+
case path.normalize('/srcDir/someOtherDir'):
42+
itemStats.isDirectory = () => true;
43+
break;
44+
case path.normalize('/srcDir/someOtherDir/file1.file'):
45+
case path.normalize('/srcDir/someOtherDir/file2.file'):
46+
itemStats.isDirectory = () => false;
47+
break;
3448
default:
3549
throw { code: 'ENOENT' };
3650
}
37-
});
51+
return itemStats;
52+
}
3853

3954
runner.registerMockExport('mkdirP', (p: string) => {
4055
console.log(`mkdirP: ${p}`);

Tasks/CopyFilesV2/Tests/L0IgnoresMakeDirError.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,33 @@ answers.find[path.normalize('/srcDir')] = [
2323
path.normalize('/srcDir/someOtherDir/file2.file'),
2424
];
2525
runner.setAnswers(answers);
26-
runner.registerMockExport('stats', (itemPath: string) => {
27-
console.log('##vso[task.debug]stats ' + itemPath);
26+
27+
fs.existsSync = (itemPath: string) => {
2828
switch (itemPath) {
2929
case path.normalize('/srcDir/someOtherDir'):
30-
return { isDirectory: () => true };
3130
case path.normalize('/srcDir/someOtherDir/file1.file'):
3231
case path.normalize('/srcDir/someOtherDir/file2.file'):
33-
return { isDirectory: () => false };
32+
return true;
33+
default:
34+
return false;
35+
}
36+
}
37+
38+
fs.statSync = (itemPath: string) => {
39+
const itemStats: fs.Stats = new fs.Stats();
40+
switch (itemPath) {
41+
case path.normalize('/srcDir/someOtherDir'):
42+
itemStats.isDirectory = () => true;
43+
break;
44+
case path.normalize('/srcDir/someOtherDir/file1.file'):
45+
case path.normalize('/srcDir/someOtherDir/file2.file'):
46+
itemStats.isDirectory = () => false;
47+
break;
3448
default:
3549
throw { code: 'ENOENT' };
3650
}
37-
});
51+
return itemStats;
52+
}
3853

3954
runner.registerMockExport('mkdirP', (p: string) => {
4055
console.log(`mkdirP: ${p}`);

Tasks/CopyFilesV2/Tests/L0cleansIfSpecified.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,38 @@ answers.find[path.normalize('/srcDir')] = [
2525
answers.rmRF[path.join(path.normalize('/destDir/clean-subDir'))] = { success: true };
2626
answers.rmRF[path.join(path.normalize('/destDir/clean-file.txt'))] = { success: true };
2727
runner.setAnswers(answers);
28-
runner.registerMockExport('stats', (itemPath: string) => {
29-
console.log('##vso[task.debug]stats ' + itemPath);
28+
29+
fs.existsSync = (itemPath: string) => {
3030
switch (itemPath) {
3131
case path.normalize('/destDir'):
32-
return { isDirectory: () => true };
3332
case path.normalize('/srcDir'):
3433
case path.normalize('/srcDir/someOtherDir'):
35-
return { isDirectory: () => true };
3634
case path.normalize('/srcDir/someOtherDir/file1.file'):
3735
case path.normalize('/srcDir/someOtherDir/file2.file'):
38-
return { isDirectory: () => false };
36+
return true;
37+
default:
38+
return false;
39+
}
40+
}
41+
42+
fs.statSync = (itemPath: string) => {
43+
const itemStats: fs.Stats = new fs.Stats();
44+
switch (itemPath) {
45+
case path.normalize('/destDir'):
46+
case path.normalize('/srcDir'):
47+
case path.normalize('/srcDir/someOtherDir'):
48+
itemStats.isDirectory = () => true;
49+
break;
50+
case path.normalize('/srcDir/someOtherDir/file1.file'):
51+
case path.normalize('/srcDir/someOtherDir/file2.file'):
52+
itemStats.isDirectory = () => false;
53+
break;
3954
default:
4055
throw { code: 'ENOENT' };
4156
}
42-
});
57+
return itemStats;
58+
}
59+
4360
let origReaddirSync = fs.readdirSync;
4461
fs.readdirSync = (p: fs.PathLike, o?: any): any => {
4562
console.log('HERE path ' + p);

Tasks/CopyFilesV2/Tests/L0cleansIfSpecifiedAndTargetIsFile.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,37 @@ answers.find[path.normalize('/srcDir')] = [
2424
];
2525
answers.rmRF[path.join(path.normalize('/destDir'))] = { success: true };
2626
runner.setAnswers(answers);
27-
runner.registerMockExport('stats', (itemPath: string) => {
28-
console.log('##vso[task.debug]stats ' + itemPath);
27+
28+
fs.existsSync = (itemPath: string) => {
2929
switch (itemPath) {
30+
case path.normalize('/srcDir'):
31+
case path.normalize('/srcDir/someOtherDir'):
3032
case path.normalize('/destDir'):
31-
return { isDirectory: () => false };
33+
case path.normalize('/srcDir/someOtherDir/file1.file'):
34+
case path.normalize('/srcDir/someOtherDir/file2.file'):
35+
return true;
36+
default:
37+
return false;
38+
}
39+
}
40+
41+
fs.statSync = (itemPath: string) => {
42+
const itemStats: fs.Stats = new fs.Stats();
43+
switch (itemPath) {
3244
case path.normalize('/srcDir'):
3345
case path.normalize('/srcDir/someOtherDir'):
34-
return { isDirectory: () => true };
46+
itemStats.isDirectory = () => true;
47+
break;
48+
case path.normalize('/destDir'):
3549
case path.normalize('/srcDir/someOtherDir/file1.file'):
3650
case path.normalize('/srcDir/someOtherDir/file2.file'):
37-
return { isDirectory: () => false };
51+
itemStats.isDirectory = () => false;
52+
break;
3853
default:
3954
throw { code: 'ENOENT' };
4055
}
41-
});
56+
return itemStats;
57+
}
4258

4359
// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
4460
fs.chmodSync = null;

Tasks/CopyFilesV2/Tests/L0copyAllFiles.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,44 @@ answers.find[path.normalize('/srcDir')] = [
2727
path.normalize('/srcDir/someOtherDir3'),
2828
];
2929
runner.setAnswers(answers);
30-
runner.registerMockExport('stats', (itemPath: string) => {
31-
console.log('##vso[task.debug]stats ' + itemPath);
30+
31+
fs.existsSync = (itemPath: string) => {
32+
switch (itemPath) {
33+
case path.normalize('/srcDir'):
34+
case path.normalize('/srcDir/someOtherDir'):
35+
case path.normalize('/srcDir/someOtherDir/file1.file'):
36+
case path.normalize('/srcDir/someOtherDir/file2.file'):
37+
case path.normalize('/srcDir/someOtherDir2'):
38+
case path.normalize('/srcDir/someOtherDir2/file1.file'):
39+
case path.normalize('/srcDir/someOtherDir2/file2.file'):
40+
case path.normalize('/srcDir/someOtherDir2/file3.file'):
41+
case path.normalize('/srcDir/someOtherDir3'):
42+
return true;
43+
default:
44+
return false;
45+
}
46+
}
47+
48+
fs.statSync = (itemPath: string) => {
49+
const itemStats: fs.Stats = new fs.Stats();
3250
switch (itemPath) {
3351
case path.normalize('/srcDir/someOtherDir'):
3452
case path.normalize('/srcDir/someOtherDir2'):
3553
case path.normalize('/srcDir/someOtherDir3'):
36-
return { isDirectory: () => true };
54+
itemStats.isDirectory = () => true;
55+
break;
3756
case path.normalize('/srcDir/someOtherDir/file1.file'):
3857
case path.normalize('/srcDir/someOtherDir/file2.file'):
3958
case path.normalize('/srcDir/someOtherDir2/file1.file'):
4059
case path.normalize('/srcDir/someOtherDir2/file2.file'):
4160
case path.normalize('/srcDir/someOtherDir2/file3.file'):
42-
return { isDirectory: () => false };
61+
itemStats.isDirectory = () => false;
62+
break;
4363
default:
4464
throw { code: 'ENOENT' };
4565
}
46-
});
66+
return itemStats;
67+
}
4768

4869
// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
4970
fs.chmodSync = null;

Tasks/CopyFilesV2/Tests/L0copyAllFilesWithBracketsInSrcPath.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,43 @@ answers.find[path.normalize('/srcDir [bracket]')] = [
2727
path.normalize('/srcDir [bracket]/someOtherDir3'),
2828
];
2929
runner.setAnswers(answers);
30-
runner.registerMockExport('stats', (itemPath: string) => {
31-
console.log('##vso[task.debug]stats ' + itemPath);
30+
31+
fs.existsSync = (itemPath: string) => {
32+
switch (itemPath) {
33+
case path.normalize('/srcDir [bracket]/someOtherDir'):
34+
case path.normalize('/srcDir [bracket]/someOtherDir2'):
35+
case path.normalize('/srcDir [bracket]/someOtherDir3'):
36+
case path.normalize('/srcDir [bracket]/someOtherDir/file1.file'):
37+
case path.normalize('/srcDir [bracket]/someOtherDir/file2.file'):
38+
case path.normalize('/srcDir [bracket]/someOtherDir2/file1.file'):
39+
case path.normalize('/srcDir [bracket]/someOtherDir2/file2.file'):
40+
case path.normalize('/srcDir [bracket]/someOtherDir2/file3.file'):
41+
return true;
42+
default:
43+
return false;
44+
}
45+
}
46+
47+
fs.statSync = (itemPath: string) => {
48+
const itemStats: fs.Stats = new fs.Stats();
3249
switch (itemPath) {
3350
case path.normalize('/srcDir [bracket]/someOtherDir'):
3451
case path.normalize('/srcDir [bracket]/someOtherDir2'):
3552
case path.normalize('/srcDir [bracket]/someOtherDir3'):
36-
return { isDirectory: () => true };
53+
itemStats.isDirectory = () => true;
54+
break;
3755
case path.normalize('/srcDir [bracket]/someOtherDir/file1.file'):
3856
case path.normalize('/srcDir [bracket]/someOtherDir/file2.file'):
3957
case path.normalize('/srcDir [bracket]/someOtherDir2/file1.file'):
4058
case path.normalize('/srcDir [bracket]/someOtherDir2/file2.file'):
4159
case path.normalize('/srcDir [bracket]/someOtherDir2/file3.file'):
42-
return { isDirectory: () => false };
60+
itemStats.isDirectory = () => false;
61+
break;
4362
default:
4463
throw { code: 'ENOENT' };
4564
}
46-
});
65+
return itemStats;
66+
}
4767

4868
// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
4969
fs.chmodSync = null;

Tasks/CopyFilesV2/Tests/L0copySubtractExclude.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,43 @@ answers.find[path.normalize('/srcDir')] = [
2828
path.normalize('/srcDir/someOtherDir3'),
2929
];
3030
runner.setAnswers(answers);
31-
runner.registerMockExport('stats', (itemPath: string) => {
32-
console.log('##vso[task.debug]stats ' + itemPath);
31+
32+
fs.existsSync = (itemPath: string) => {
33+
switch (itemPath) {
34+
case path.normalize('/srcDir/someOtherDir'):
35+
case path.normalize('/srcDir/someOtherDir2'):
36+
case path.normalize('/srcDir/someOtherDir3'):
37+
case path.normalize('/srcDir/someOtherDir/file1.file'):
38+
case path.normalize('/srcDir/someOtherDir/file2.file'):
39+
case path.normalize('/srcDir/someOtherDir2/file1.file'):
40+
case path.normalize('/srcDir/someOtherDir2/file2.file'):
41+
case path.normalize('/srcDir/someOtherDir2/file3.file'):
42+
return true;
43+
default:
44+
return false;
45+
}
46+
}
47+
48+
fs.statSync = (itemPath: string) => {
49+
const itemStats: fs.Stats = new fs.Stats();
3350
switch (itemPath) {
3451
case path.normalize('/srcDir/someOtherDir'):
3552
case path.normalize('/srcDir/someOtherDir2'):
3653
case path.normalize('/srcDir/someOtherDir3'):
37-
return { isDirectory: () => true };
54+
itemStats.isDirectory = () => true;
55+
break;
3856
case path.normalize('/srcDir/someOtherDir/file1.file'):
3957
case path.normalize('/srcDir/someOtherDir/file2.file'):
4058
case path.normalize('/srcDir/someOtherDir2/file1.file'):
4159
case path.normalize('/srcDir/someOtherDir2/file2.file'):
4260
case path.normalize('/srcDir/someOtherDir2/file3.file'):
43-
return { isDirectory: () => false };
61+
itemStats.isDirectory = () => false;
62+
break;
4463
default:
4564
throw { code: 'ENOENT' };
4665
}
47-
});
66+
return itemStats;
67+
}
4868

4969
// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
5070
fs.chmodSync = null;

Tasks/CopyFilesV2/Tests/L0failsIfTargetFileIsDir.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,35 @@ answers.find[path.normalize('/srcDir')] = [
2222
path.normalize('/srcDir/someOtherDir/file2.file'),
2323
];
2424
runner.setAnswers(answers);
25-
runner.registerMockExport('stats', (itemPath: string) => {
26-
console.log('##vso[task.debug]stats ' + itemPath);
25+
26+
fs.existsSync = (itemPath: string) => {
27+
switch (itemPath) {
28+
case path.normalize('/srcDir/someOtherDir'):
29+
case path.normalize('/destDir/someOtherDir/file1.file'):
30+
case path.normalize('/srcDir/someOtherDir/file1.file'):
31+
case path.normalize('/srcDir/someOtherDir/file2.file'):
32+
return true;
33+
default:
34+
return false;
35+
}
36+
}
37+
38+
fs.statSync = (itemPath: string) => {
39+
const itemStats: fs.Stats = new fs.Stats();
2740
switch (itemPath) {
2841
case path.normalize('/srcDir/someOtherDir'):
2942
case path.normalize('/destDir/someOtherDir/file1.file'):
30-
return { isDirectory: () => true };
43+
itemStats.isDirectory = () => true;
44+
break;
3145
case path.normalize('/srcDir/someOtherDir/file1.file'):
3246
case path.normalize('/srcDir/someOtherDir/file2.file'):
33-
return { isDirectory: () => false };
47+
itemStats.isDirectory = () => false;
48+
break;
3449
default:
3550
throw { code: 'ENOENT' };
3651
}
37-
});
52+
return itemStats;
53+
}
3854

3955
// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
4056
fs.chmodSync = null;

0 commit comments

Comments
 (0)