azure-pipelines-task-lib 5.2.7 → 5.2.8

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.
@@ -1,4 +1,5 @@
1
1
  {
2
+ "loc.messages.LIB_CopyDirectoryWithoutRecursiveOption": "cp: cannot copy a directory '%s' without the recursive option",
2
3
  "loc.messages.LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s",
3
4
  "loc.messages.LIB_DirectoryStackEmpty": "Directory stack is empty",
4
5
  "loc.messages.LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s",
package/lib.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "messages": {
3
+ "LIB_CopyDirectoryWithoutRecursiveOption": "cp: cannot copy a directory '%s' without the recursive option",
3
4
  "LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s",
4
5
  "LIB_DirectoryStackEmpty": "Directory stack is empty",
5
6
  "LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azure-pipelines-task-lib",
3
- "version": "5.2.7",
3
+ "version": "5.2.8",
4
4
  "description": "Azure Pipelines Task SDK",
5
5
  "main": "./task.js",
6
6
  "typings": "./task.d.ts",
package/task.js CHANGED
@@ -1042,30 +1042,33 @@ function cp(sourceOrOptions, destinationOrSource, optionsOrDestination, continue
1042
1042
  if (!fs.existsSync(destination) && !force) {
1043
1043
  throw new Error((0, exports.loc)('LIB_PathNotFound', 'cp', destination));
1044
1044
  }
1045
+ var hasGlobPattern = /[*?{[!@#]/.test(source);
1046
+ if (hasGlobPattern) {
1047
+ var sourcesToProcess = [];
1048
+ var sourceDir = path.dirname(source);
1049
+ sourceDir = sourceDir == '.' ? path.resolve() : sourceDir;
1050
+ sourcesToProcess = findMatch(sourceDir, [path.basename(source)]);
1051
+ if (sourcesToProcess.length === 0) {
1052
+ (0, exports.debug)("No matches found for glob pattern: ".concat(source));
1053
+ }
1054
+ for (var _i = 0, sourcesToProcess_1 = sourcesToProcess; _i < sourcesToProcess_1.length; _i++) {
1055
+ var src = sourcesToProcess_1[_i];
1056
+ cp(src, destination, options, continueOnError, retryCount);
1057
+ }
1058
+ return;
1059
+ }
1045
1060
  var lstatSource = fs.lstatSync(source);
1061
+ if (!recursive && lstatSource.isDirectory()) {
1062
+ throw new Error((0, exports.loc)('LIB_CopyDirectoryWithoutRecursiveOption', source));
1063
+ }
1046
1064
  if (!force && fs.existsSync(destination)) {
1047
1065
  return;
1048
1066
  }
1049
1067
  try {
1050
- if (lstatSource.isSymbolicLink()) {
1051
- var symlinkTarget = fs.readlinkSync(source);
1052
- source = path.resolve(path.dirname(source), symlinkTarget);
1053
- lstatSource = fs.lstatSync(source);
1054
- }
1055
- if (lstatSource.isFile()) {
1056
- if (fs.existsSync(destination) && fs.lstatSync(destination).isDirectory()) {
1057
- destination = path.join(destination, path.basename(source));
1058
- }
1059
- if (force) {
1060
- fs.copyFileSync(source, destination);
1061
- }
1062
- else {
1063
- fs.copyFileSync(source, destination, fs.constants.COPYFILE_EXCL);
1064
- }
1065
- }
1066
- else {
1067
- copyDirectoryWithResolvedSymlinks(source, path.join(destination, path.basename(source)), force);
1068
+ if (fs.existsSync(destination) && fs.lstatSync(destination).isDirectory()) {
1069
+ destination = path.join(destination, path.basename(source));
1068
1070
  }
1071
+ copyWithPreservedSymlinks(source, destination, force);
1069
1072
  }
1070
1073
  catch (error) {
1071
1074
  throw new Error((0, exports.loc)('LIB_OperationFailed', 'cp', error));
@@ -1073,38 +1076,39 @@ function cp(sourceOrOptions, destinationOrSource, optionsOrDestination, continue
1073
1076
  }, [], { retryCount: retryCount, continueOnError: continueOnError });
1074
1077
  }
1075
1078
  exports.cp = cp;
1076
- var copyDirectoryWithResolvedSymlinks = function (src, dest, force) {
1077
- var srcPath;
1078
- var destPath;
1079
- var entry;
1080
- var entries = fs.readdirSync(src, { withFileTypes: true });
1081
- if (!fs.existsSync(dest)) {
1082
- fs.mkdirSync(dest, { recursive: true });
1083
- }
1084
- for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
1085
- entry = entries_1[_i];
1086
- srcPath = path.join(src, entry.name);
1087
- destPath = path.join(dest, entry.name);
1088
- if (entry.isSymbolicLink()) {
1089
- // Resolve the symbolic link and copy the target
1090
- var symlinkTarget = fs.readlinkSync(srcPath);
1091
- var resolvedPath = path.resolve(path.dirname(srcPath), symlinkTarget);
1092
- var stat = fs.lstatSync(resolvedPath);
1093
- if (stat.isFile()) {
1094
- // Use the actual target file's name instead of the symbolic link's name
1095
- var targetFileName = path.basename(resolvedPath);
1096
- var targetDestPath = path.join(dest, targetFileName);
1097
- fs.copyFileSync(resolvedPath, targetDestPath);
1079
+ var copyWithPreservedSymlinks = function (source, destination, force) {
1080
+ var lstatSource = fs.lstatSync(source);
1081
+ if (lstatSource.isSymbolicLink()) {
1082
+ var symlinkTarget = fs.readlinkSync(source);
1083
+ if (force && fs.existsSync(destination)) {
1084
+ var destStats = fs.lstatSync(destination);
1085
+ if (destStats.isSymbolicLink()) {
1086
+ fs.unlinkSync(destination);
1098
1087
  }
1099
- else if (stat.isDirectory()) {
1100
- copyDirectoryWithResolvedSymlinks(resolvedPath, destPath, force);
1088
+ else {
1089
+ fs.rmSync(destination, { recursive: true, force: true });
1101
1090
  }
1102
1091
  }
1103
- else if (entry.isFile()) {
1104
- fs.copyFileSync(srcPath, destPath);
1092
+ fs.symlinkSync(symlinkTarget, destination);
1093
+ }
1094
+ else if (lstatSource.isFile()) {
1095
+ if (force) {
1096
+ fs.copyFileSync(source, destination);
1105
1097
  }
1106
- else if (entry.isDirectory()) {
1107
- copyDirectoryWithResolvedSymlinks(srcPath, destPath, force);
1098
+ else {
1099
+ fs.copyFileSync(source, destination, fs.constants.COPYFILE_EXCL);
1100
+ }
1101
+ }
1102
+ else {
1103
+ var entries = fs.readdirSync(source, { withFileTypes: true });
1104
+ if (!fs.existsSync(destination)) {
1105
+ fs.mkdirSync(destination, { recursive: true });
1106
+ }
1107
+ for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
1108
+ var entry = entries_1[_i];
1109
+ var srcPath = path.join(source, entry.name);
1110
+ var destPath = path.join(destination, entry.name);
1111
+ copyWithPreservedSymlinks(srcPath, destPath, force);
1108
1112
  }
1109
1113
  }
1110
1114
  };