Skip to content

Commit 12f2f1f

Browse files
authored
Rollback CopyFilesV2 (#16715)
* Revert "Fix stats function in the CopyFilesV2 task (#16453)" This reverts commit 01d5748. * update CopyFilesV2 task version
1 parent 21e1ac3 commit 12f2f1f

16 files changed

+100
-332
lines changed

Tasks/CopyFilesV2/Tests/L0FailsIfThereIsMkdirError.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,18 @@ answers.find[path.normalize('/srcDir')] = [
2323
path.normalize('/srcDir/someOtherDir/file2.file'),
2424
];
2525
runner.setAnswers(answers);
26-
27-
fs.existsSync = (itemPath: string) => {
26+
runner.registerMockExport('stats', (itemPath: string) => {
27+
console.log('##vso[task.debug]stats ' + itemPath);
2828
switch (itemPath) {
2929
case path.normalize('/srcDir/someOtherDir'):
30+
return { isDirectory: () => true };
3031
case path.normalize('/srcDir/someOtherDir/file1.file'):
3132
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();
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;
33+
return { isDirectory: () => false };
4834
default:
4935
throw { code: 'ENOENT' };
5036
}
51-
return itemStats;
52-
}
37+
});
5338

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

Tasks/CopyFilesV2/Tests/L0IgnoresMakeDirError.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,18 @@ answers.find[path.normalize('/srcDir')] = [
2323
path.normalize('/srcDir/someOtherDir/file2.file'),
2424
];
2525
runner.setAnswers(answers);
26-
27-
fs.existsSync = (itemPath: string) => {
26+
runner.registerMockExport('stats', (itemPath: string) => {
27+
console.log('##vso[task.debug]stats ' + itemPath);
2828
switch (itemPath) {
2929
case path.normalize('/srcDir/someOtherDir'):
30+
return { isDirectory: () => true };
3031
case path.normalize('/srcDir/someOtherDir/file1.file'):
3132
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();
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;
33+
return { isDirectory: () => false };
4834
default:
4935
throw { code: 'ENOENT' };
5036
}
51-
return itemStats;
52-
}
37+
});
5338

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

Tasks/CopyFilesV2/Tests/L0cleansIfSpecified.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,21 @@ 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-
29-
fs.existsSync = (itemPath: string) => {
28+
runner.registerMockExport('stats', (itemPath: string) => {
29+
console.log('##vso[task.debug]stats ' + itemPath);
3030
switch (itemPath) {
3131
case path.normalize('/destDir'):
32+
return { isDirectory: () => true };
3233
case path.normalize('/srcDir'):
3334
case path.normalize('/srcDir/someOtherDir'):
35+
return { isDirectory: () => true };
3436
case path.normalize('/srcDir/someOtherDir/file1.file'):
3537
case path.normalize('/srcDir/someOtherDir/file2.file'):
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;
38+
return { isDirectory: () => false };
5439
default:
5540
throw { code: 'ENOENT' };
5641
}
57-
return itemStats;
58-
}
59-
42+
});
6043
let origReaddirSync = fs.readdirSync;
6144
fs.readdirSync = (p: fs.PathLike, o?: any): any => {
6245
console.log('HERE path ' + p);

Tasks/CopyFilesV2/Tests/L0cleansIfSpecifiedAndTargetIsFile.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,21 @@ answers.find[path.normalize('/srcDir')] = [
2424
];
2525
answers.rmRF[path.join(path.normalize('/destDir'))] = { success: true };
2626
runner.setAnswers(answers);
27-
28-
fs.existsSync = (itemPath: string) => {
27+
runner.registerMockExport('stats', (itemPath: string) => {
28+
console.log('##vso[task.debug]stats ' + itemPath);
2929
switch (itemPath) {
30-
case path.normalize('/srcDir'):
31-
case path.normalize('/srcDir/someOtherDir'):
3230
case path.normalize('/destDir'):
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) {
31+
return { isDirectory: () => false };
4432
case path.normalize('/srcDir'):
4533
case path.normalize('/srcDir/someOtherDir'):
46-
itemStats.isDirectory = () => true;
47-
break;
48-
case path.normalize('/destDir'):
34+
return { isDirectory: () => true };
4935
case path.normalize('/srcDir/someOtherDir/file1.file'):
5036
case path.normalize('/srcDir/someOtherDir/file2.file'):
51-
itemStats.isDirectory = () => false;
52-
break;
37+
return { isDirectory: () => false };
5338
default:
5439
throw { code: 'ENOENT' };
5540
}
56-
return itemStats;
57-
}
41+
});
5842

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

Tasks/CopyFilesV2/Tests/L0copyAllFiles.ts

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,23 @@ answers.find[path.normalize('/srcDir')] = [
2727
path.normalize('/srcDir/someOtherDir3'),
2828
];
2929
runner.setAnswers(answers);
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();
30+
runner.registerMockExport('stats', (itemPath: string) => {
31+
console.log('##vso[task.debug]stats ' + itemPath);
5032
switch (itemPath) {
5133
case path.normalize('/srcDir/someOtherDir'):
5234
case path.normalize('/srcDir/someOtherDir2'):
5335
case path.normalize('/srcDir/someOtherDir3'):
54-
itemStats.isDirectory = () => true;
55-
break;
36+
return { isDirectory: () => true };
5637
case path.normalize('/srcDir/someOtherDir/file1.file'):
5738
case path.normalize('/srcDir/someOtherDir/file2.file'):
5839
case path.normalize('/srcDir/someOtherDir2/file1.file'):
5940
case path.normalize('/srcDir/someOtherDir2/file2.file'):
6041
case path.normalize('/srcDir/someOtherDir2/file3.file'):
61-
itemStats.isDirectory = () => false;
62-
break;
42+
return { isDirectory: () => false };
6343
default:
6444
throw { code: 'ENOENT' };
6545
}
66-
return itemStats;
67-
}
46+
});
6847

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

Tasks/CopyFilesV2/Tests/L0copyAllFilesWithBracketsInSrcPath.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,23 @@ answers.find[path.normalize('/srcDir [bracket]')] = [
2727
path.normalize('/srcDir [bracket]/someOtherDir3'),
2828
];
2929
runner.setAnswers(answers);
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();
30+
runner.registerMockExport('stats', (itemPath: string) => {
31+
console.log('##vso[task.debug]stats ' + itemPath);
4932
switch (itemPath) {
5033
case path.normalize('/srcDir [bracket]/someOtherDir'):
5134
case path.normalize('/srcDir [bracket]/someOtherDir2'):
5235
case path.normalize('/srcDir [bracket]/someOtherDir3'):
53-
itemStats.isDirectory = () => true;
54-
break;
36+
return { isDirectory: () => true };
5537
case path.normalize('/srcDir [bracket]/someOtherDir/file1.file'):
5638
case path.normalize('/srcDir [bracket]/someOtherDir/file2.file'):
5739
case path.normalize('/srcDir [bracket]/someOtherDir2/file1.file'):
5840
case path.normalize('/srcDir [bracket]/someOtherDir2/file2.file'):
5941
case path.normalize('/srcDir [bracket]/someOtherDir2/file3.file'):
60-
itemStats.isDirectory = () => false;
61-
break;
42+
return { isDirectory: () => false };
6243
default:
6344
throw { code: 'ENOENT' };
6445
}
65-
return itemStats;
66-
}
46+
});
6747

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

Tasks/CopyFilesV2/Tests/L0copySubtractExclude.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,23 @@ answers.find[path.normalize('/srcDir')] = [
2828
path.normalize('/srcDir/someOtherDir3'),
2929
];
3030
runner.setAnswers(answers);
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();
31+
runner.registerMockExport('stats', (itemPath: string) => {
32+
console.log('##vso[task.debug]stats ' + itemPath);
5033
switch (itemPath) {
5134
case path.normalize('/srcDir/someOtherDir'):
5235
case path.normalize('/srcDir/someOtherDir2'):
5336
case path.normalize('/srcDir/someOtherDir3'):
54-
itemStats.isDirectory = () => true;
55-
break;
37+
return { isDirectory: () => true };
5638
case path.normalize('/srcDir/someOtherDir/file1.file'):
5739
case path.normalize('/srcDir/someOtherDir/file2.file'):
5840
case path.normalize('/srcDir/someOtherDir2/file1.file'):
5941
case path.normalize('/srcDir/someOtherDir2/file2.file'):
6042
case path.normalize('/srcDir/someOtherDir2/file3.file'):
61-
itemStats.isDirectory = () => false;
62-
break;
43+
return { isDirectory: () => false };
6344
default:
6445
throw { code: 'ENOENT' };
6546
}
66-
return itemStats;
67-
}
47+
});
6848

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

Tasks/CopyFilesV2/Tests/L0failsIfTargetFileIsDir.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,19 @@ answers.find[path.normalize('/srcDir')] = [
2222
path.normalize('/srcDir/someOtherDir/file2.file'),
2323
];
2424
runner.setAnswers(answers);
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();
25+
runner.registerMockExport('stats', (itemPath: string) => {
26+
console.log('##vso[task.debug]stats ' + itemPath);
4027
switch (itemPath) {
4128
case path.normalize('/srcDir/someOtherDir'):
4229
case path.normalize('/destDir/someOtherDir/file1.file'):
43-
itemStats.isDirectory = () => true;
44-
break;
30+
return { isDirectory: () => true };
4531
case path.normalize('/srcDir/someOtherDir/file1.file'):
4632
case path.normalize('/srcDir/someOtherDir/file2.file'):
47-
itemStats.isDirectory = () => false;
48-
break;
33+
return { isDirectory: () => false };
4934
default:
5035
throw { code: 'ENOENT' };
5136
}
52-
return itemStats;
53-
}
37+
});
5438

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

0 commit comments

Comments
 (0)