azure-pipelines-task-lib 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/task.js +96 -58
package/package.json
CHANGED
package/task.js
CHANGED
|
@@ -929,6 +929,7 @@ function ls(optionsOrPaths) {
|
|
|
929
929
|
if (paths.length === 0) {
|
|
930
930
|
paths.push(path.resolve('.'));
|
|
931
931
|
}
|
|
932
|
+
var pathsCopy = __spreadArray([], paths, true);
|
|
932
933
|
var preparedPaths = [];
|
|
933
934
|
try {
|
|
934
935
|
var _loop_1 = function () {
|
|
@@ -958,11 +959,13 @@ function ls(optionsOrPaths) {
|
|
|
958
959
|
if (!includeHidden && entrybasename.startsWith('.') && entrybasename !== '.' && entrybasename !== '..') {
|
|
959
960
|
return "continue";
|
|
960
961
|
}
|
|
962
|
+
var baseDir = pathsCopy.find(function (p) { return entry.startsWith(path.resolve(p)); }) || path.resolve('.');
|
|
961
963
|
if (fs.lstatSync(entry).isDirectory() && isRecursive) {
|
|
962
964
|
preparedPaths.push.apply(preparedPaths, fs.readdirSync(entry).map(function (x) { return path.join(entry, x); }));
|
|
965
|
+
entries.push(path.relative(baseDir, entry));
|
|
963
966
|
}
|
|
964
967
|
else {
|
|
965
|
-
entries.push(entry);
|
|
968
|
+
entries.push(path.relative(baseDir, entry));
|
|
966
969
|
}
|
|
967
970
|
};
|
|
968
971
|
while (preparedPaths.length > 0) {
|
|
@@ -1020,6 +1023,10 @@ function cp(sourceOrOptions, destinationOrSource, optionsOrDestination, continue
|
|
|
1020
1023
|
return;
|
|
1021
1024
|
}
|
|
1022
1025
|
try {
|
|
1026
|
+
if (lstatSource.isSymbolicLink()) {
|
|
1027
|
+
source = fs.readlinkSync(source);
|
|
1028
|
+
lstatSource = fs.lstatSync(source);
|
|
1029
|
+
}
|
|
1023
1030
|
if (lstatSource.isFile()) {
|
|
1024
1031
|
if (fs.existsSync(destination) && fs.lstatSync(destination).isDirectory()) {
|
|
1025
1032
|
destination = path.join(destination, path.basename(source));
|
|
@@ -1032,7 +1039,7 @@ function cp(sourceOrOptions, destinationOrSource, optionsOrDestination, continue
|
|
|
1032
1039
|
}
|
|
1033
1040
|
}
|
|
1034
1041
|
else {
|
|
1035
|
-
|
|
1042
|
+
copyDirectoryWithResolvedSymlinks(source, path.join(destination, path.basename(source)), force);
|
|
1036
1043
|
}
|
|
1037
1044
|
}
|
|
1038
1045
|
catch (error) {
|
|
@@ -1041,6 +1048,40 @@ function cp(sourceOrOptions, destinationOrSource, optionsOrDestination, continue
|
|
|
1041
1048
|
}, [], { retryCount: retryCount, continueOnError: continueOnError });
|
|
1042
1049
|
}
|
|
1043
1050
|
exports.cp = cp;
|
|
1051
|
+
var copyDirectoryWithResolvedSymlinks = function (src, dest, force) {
|
|
1052
|
+
var srcPath;
|
|
1053
|
+
var destPath;
|
|
1054
|
+
var entry;
|
|
1055
|
+
var entries = fs.readdirSync(src, { withFileTypes: true });
|
|
1056
|
+
if (!fs.existsSync(dest)) {
|
|
1057
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
1058
|
+
}
|
|
1059
|
+
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
|
1060
|
+
entry = entries_1[_i];
|
|
1061
|
+
srcPath = path.join(src, entry.name);
|
|
1062
|
+
destPath = path.join(dest, entry.name);
|
|
1063
|
+
if (entry.isSymbolicLink()) {
|
|
1064
|
+
// Resolve the symbolic link and copy the target
|
|
1065
|
+
var resolvedPath = fs.readlinkSync(srcPath);
|
|
1066
|
+
var stat = fs.lstatSync(resolvedPath);
|
|
1067
|
+
if (stat.isFile()) {
|
|
1068
|
+
// Use the actual target file's name instead of the symbolic link's name
|
|
1069
|
+
var targetFileName = path.basename(resolvedPath);
|
|
1070
|
+
var targetDestPath = path.join(dest, targetFileName);
|
|
1071
|
+
fs.copyFileSync(resolvedPath, targetDestPath);
|
|
1072
|
+
}
|
|
1073
|
+
else if (stat.isDirectory()) {
|
|
1074
|
+
copyDirectoryWithResolvedSymlinks(resolvedPath, destPath, force);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
else if (entry.isFile()) {
|
|
1078
|
+
fs.copyFileSync(srcPath, destPath);
|
|
1079
|
+
}
|
|
1080
|
+
else if (entry.isDirectory()) {
|
|
1081
|
+
copyDirectoryWithResolvedSymlinks(srcPath, destPath, force);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1044
1085
|
/**
|
|
1045
1086
|
* Moves a path.
|
|
1046
1087
|
*
|
|
@@ -1452,90 +1493,87 @@ function rmRF(inputPath) {
|
|
|
1452
1493
|
// Node doesn't provide a delete operation, only an unlink function. This means that if the file is being used by another
|
|
1453
1494
|
// program (e.g. antivirus), it won't be deleted. To address this, we shell out the work to rd/del.
|
|
1454
1495
|
try {
|
|
1455
|
-
|
|
1496
|
+
var lstats = fs.lstatSync(inputPath);
|
|
1497
|
+
if (lstats.isDirectory() && !lstats.isSymbolicLink()) {
|
|
1456
1498
|
(0, exports.debug)('removing directory ' + inputPath);
|
|
1457
1499
|
childProcess.execFileSync("cmd.exe", ["/c", "rd", "/s", "/q", inputPath]);
|
|
1458
1500
|
}
|
|
1501
|
+
else if (lstats.isSymbolicLink()) {
|
|
1502
|
+
(0, exports.debug)('removing symbolic link ' + inputPath);
|
|
1503
|
+
var realPath = fs.readlinkSync(inputPath);
|
|
1504
|
+
if (fs.existsSync(realPath)) {
|
|
1505
|
+
var stats_3 = fs.statSync(realPath);
|
|
1506
|
+
if (stats_3.isDirectory()) {
|
|
1507
|
+
childProcess.execFileSync("cmd.exe", ["/c", "rd", "/s", "/q", realPath]);
|
|
1508
|
+
fs.unlinkSync(inputPath);
|
|
1509
|
+
}
|
|
1510
|
+
else {
|
|
1511
|
+
fs.unlinkSync(inputPath);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
else {
|
|
1515
|
+
(0, exports.debug)("Symbolic link '".concat(inputPath, "' points to a non-existing target '").concat(realPath, "'. Removing the symbolic link."));
|
|
1516
|
+
fs.unlinkSync(inputPath);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1459
1519
|
else {
|
|
1460
1520
|
(0, exports.debug)('removing file ' + inputPath);
|
|
1461
1521
|
childProcess.execFileSync("cmd.exe", ["/c", "del", "/f", "/a", inputPath]);
|
|
1462
1522
|
}
|
|
1463
1523
|
}
|
|
1464
1524
|
catch (err) {
|
|
1465
|
-
|
|
1466
|
-
// other errors are valid
|
|
1467
|
-
if (err.code != 'ENOENT') {
|
|
1468
|
-
throw new Error((0, exports.loc)('LIB_OperationFailed', 'rmRF', err.message));
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
// Shelling out fails to remove a symlink folder with missing source, this unlink catches that
|
|
1472
|
-
try {
|
|
1473
|
-
fs.unlinkSync(inputPath);
|
|
1474
|
-
}
|
|
1475
|
-
catch (err) {
|
|
1476
|
-
// if you try to delete a file that doesn't exist, desired result is achieved
|
|
1477
|
-
// other errors are valid
|
|
1525
|
+
(0, exports.debug)('Error: ' + err.message);
|
|
1478
1526
|
if (err.code != 'ENOENT') {
|
|
1479
1527
|
throw new Error((0, exports.loc)('LIB_OperationFailed', 'rmRF', err.message));
|
|
1480
1528
|
}
|
|
1481
1529
|
}
|
|
1482
1530
|
}
|
|
1483
1531
|
else {
|
|
1484
|
-
// get the lstats in order to workaround a bug in shelljs@0.3.0 where symlinks
|
|
1485
|
-
// with missing targets are not handled correctly by "rm('-rf', path)"
|
|
1486
1532
|
var lstats = void 0;
|
|
1487
1533
|
try {
|
|
1488
1534
|
if (inputPath.includes('*')) {
|
|
1489
1535
|
var entries = findMatch(path.dirname(inputPath), [path.basename(inputPath)]);
|
|
1490
|
-
for (var _i = 0,
|
|
1491
|
-
var entry =
|
|
1492
|
-
|
|
1536
|
+
for (var _i = 0, entries_2 = entries; _i < entries_2.length; _i++) {
|
|
1537
|
+
var entry = entries_2[_i];
|
|
1538
|
+
rmRF(entry);
|
|
1493
1539
|
}
|
|
1494
|
-
return;
|
|
1495
1540
|
}
|
|
1496
1541
|
else {
|
|
1497
1542
|
lstats = fs.lstatSync(inputPath);
|
|
1543
|
+
if (lstats.isDirectory() && !lstats.isSymbolicLink()) {
|
|
1544
|
+
(0, exports.debug)('removing directory ' + inputPath);
|
|
1545
|
+
fs.rmSync(inputPath, { recursive: true, force: true });
|
|
1546
|
+
}
|
|
1547
|
+
else if (lstats.isSymbolicLink()) {
|
|
1548
|
+
(0, exports.debug)('removing symbolic link ' + inputPath);
|
|
1549
|
+
var realPath = fs.readlinkSync(inputPath);
|
|
1550
|
+
if (fs.existsSync(realPath)) {
|
|
1551
|
+
var stats_4 = fs.statSync(realPath);
|
|
1552
|
+
if (stats_4.isDirectory()) {
|
|
1553
|
+
fs.rmSync(realPath, { recursive: true, force: true });
|
|
1554
|
+
fs.unlinkSync(inputPath);
|
|
1555
|
+
}
|
|
1556
|
+
else {
|
|
1557
|
+
fs.unlinkSync(inputPath);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
else {
|
|
1561
|
+
(0, exports.debug)("Symbolic link '".concat(inputPath, "' points to a non-existing target '").concat(realPath, "'. Removing the symbolic link."));
|
|
1562
|
+
fs.unlinkSync(inputPath);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
else {
|
|
1566
|
+
(0, exports.debug)('removing file ' + inputPath);
|
|
1567
|
+
fs.unlinkSync(inputPath);
|
|
1568
|
+
}
|
|
1498
1569
|
}
|
|
1499
1570
|
}
|
|
1500
1571
|
catch (err) {
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
return;
|
|
1505
|
-
}
|
|
1506
|
-
throw new Error((0, exports.loc)('LIB_OperationFailed', 'rmRF', err.message));
|
|
1507
|
-
}
|
|
1508
|
-
if (lstats.isDirectory()) {
|
|
1509
|
-
(0, exports.debug)('removing directory');
|
|
1510
|
-
try {
|
|
1511
|
-
fs.rmSync(inputPath, { recursive: true, force: true });
|
|
1512
|
-
}
|
|
1513
|
-
catch (errMsg) {
|
|
1514
|
-
throw new Error((0, exports.loc)('LIB_OperationFailed', 'rmRF', errMsg));
|
|
1515
|
-
}
|
|
1516
|
-
return;
|
|
1517
|
-
}
|
|
1518
|
-
else if (lstats.isSymbolicLink()) {
|
|
1519
|
-
(0, exports.debug)('removing symbolic link');
|
|
1520
|
-
try {
|
|
1521
|
-
fs.unlinkSync(inputPath);
|
|
1522
|
-
}
|
|
1523
|
-
catch (errMsg) {
|
|
1524
|
-
throw new Error((0, exports.loc)('LIB_OperationFailed', 'rmRF', errMsg));
|
|
1525
|
-
}
|
|
1526
|
-
return;
|
|
1527
|
-
}
|
|
1528
|
-
(0, exports.debug)('removing file');
|
|
1529
|
-
try {
|
|
1530
|
-
var entries = findMatch(path.dirname(inputPath), [path.basename(inputPath)]);
|
|
1531
|
-
for (var _a = 0, entries_2 = entries; _a < entries_2.length; _a++) {
|
|
1532
|
-
var entry = entries_2[_a];
|
|
1533
|
-
fs.rmSync(entry, { recursive: true, force: true });
|
|
1572
|
+
(0, exports.debug)('Error: ' + err.message);
|
|
1573
|
+
if (err.code != 'ENOENT') {
|
|
1574
|
+
throw new Error((0, exports.loc)('LIB_OperationFailed', 'rmRF', err.message));
|
|
1534
1575
|
}
|
|
1535
1576
|
}
|
|
1536
|
-
catch (err) {
|
|
1537
|
-
throw new Error((0, exports.loc)('LIB_OperationFailed', 'rmRF', err.message));
|
|
1538
|
-
}
|
|
1539
1577
|
}
|
|
1540
1578
|
}
|
|
1541
1579
|
exports.rmRF = rmRF;
|