|
|
@@ -3221,8 +3221,13 @@ bool HandleCreateLinkCommand(std::vector<std::string> const& args,
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ cmPolicies::PolicyStatus const cmp0205 =
|
|
|
+ status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0205);
|
|
|
+
|
|
|
// Hard link requires original file to exist.
|
|
|
- if (!arguments.Symbolic && !cmSystemTools::FileExists(fileName)) {
|
|
|
+ if (!arguments.Symbolic &&
|
|
|
+ (!cmSystemTools::PathExists(fileName) ||
|
|
|
+ (cmp0205 != cmPolicies::NEW && !cmSystemTools::FileExists(fileName)))) {
|
|
|
result = "Cannot hard link \'" + fileName + "\' as it does not exist.";
|
|
|
if (!arguments.Result.empty()) {
|
|
|
status.GetMakefile().AddDefinition(arguments.Result, result);
|
|
|
@@ -3234,11 +3239,17 @@ bool HandleCreateLinkCommand(std::vector<std::string> const& args,
|
|
|
|
|
|
// Check if the new file already exists and remove it.
|
|
|
if (cmSystemTools::PathExists(newFileName)) {
|
|
|
- cmsys::Status rmStatus = cmSystemTools::RemoveFile(newFileName);
|
|
|
+ cmsys::Status rmStatus;
|
|
|
+ if (cmp0205 == cmPolicies::NEW &&
|
|
|
+ cmSystemTools::FileIsDirectory(newFileName)) {
|
|
|
+ rmStatus = cmSystemTools::RepeatedRemoveDirectory(newFileName);
|
|
|
+ } else {
|
|
|
+ rmStatus = cmSystemTools::RemoveFile(newFileName);
|
|
|
+ }
|
|
|
if (!rmStatus) {
|
|
|
- auto err = cmStrCat("Failed to create link '", newFileName,
|
|
|
- "' because existing path cannot be removed: ",
|
|
|
- rmStatus.GetString(), '\n');
|
|
|
+ std::string err = cmStrCat("Failed to create link '", newFileName,
|
|
|
+ "' because existing path cannot be removed: ",
|
|
|
+ rmStatus.GetString(), '\n');
|
|
|
|
|
|
if (!arguments.Result.empty()) {
|
|
|
status.GetMakefile().AddDefinition(arguments.Result, err);
|
|
|
@@ -3249,6 +3260,8 @@ bool HandleCreateLinkCommand(std::vector<std::string> const& args,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ bool const sourceIsDirectory = cmSystemTools::FileIsDirectory(fileName);
|
|
|
+
|
|
|
// Whether the operation completed successfully.
|
|
|
bool completed = false;
|
|
|
|
|
|
@@ -3263,20 +3276,54 @@ bool HandleCreateLinkCommand(std::vector<std::string> const& args,
|
|
|
"': ", linked.GetString());
|
|
|
}
|
|
|
} else {
|
|
|
- cmsys::Status linked =
|
|
|
- cmSystemTools::CreateLinkQuietly(fileName, newFileName);
|
|
|
- if (linked) {
|
|
|
- completed = true;
|
|
|
+ bool needToTry = true;
|
|
|
+ if (sourceIsDirectory) {
|
|
|
+ if (cmp0205 == cmPolicies::NEW) {
|
|
|
+ needToTry = false;
|
|
|
+ } else if (cmp0205 == cmPolicies::WARN) {
|
|
|
+ status.GetMakefile().IssueMessage(
|
|
|
+ MessageType::AUTHOR_WARNING,
|
|
|
+ cmStrCat("Path\n ", fileName,
|
|
|
+ "\nis directory. Hardlinks creation is not supported for "
|
|
|
+ "directories.\n",
|
|
|
+ cmPolicies::GetPolicyWarning(cmPolicies::CMP0205)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (needToTry) {
|
|
|
+ cmsys::Status linked =
|
|
|
+ cmSystemTools::CreateLinkQuietly(fileName, newFileName);
|
|
|
+ if (linked) {
|
|
|
+ completed = true;
|
|
|
+ } else {
|
|
|
+ result = cmStrCat("failed to create link '", newFileName,
|
|
|
+ "': ", linked.GetString());
|
|
|
+ }
|
|
|
} else {
|
|
|
- result = cmStrCat("failed to create link '", newFileName,
|
|
|
- "': ", linked.GetString());
|
|
|
+ result =
|
|
|
+ cmStrCat("failed to create link '", newFileName, "': not supported");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (arguments.CopyOnError && cmp0205 == cmPolicies::WARN &&
|
|
|
+ sourceIsDirectory) {
|
|
|
+ status.GetMakefile().IssueMessage(
|
|
|
+ MessageType::AUTHOR_WARNING,
|
|
|
+ cmStrCat("Path\n ", fileName,
|
|
|
+ "\nis directory. It will be copied recursively when NEW policy "
|
|
|
+ "behavior applies for CMP0205.\n",
|
|
|
+ cmPolicies::GetPolicyWarning(cmPolicies::CMP0205)));
|
|
|
+ }
|
|
|
+
|
|
|
// Check if copy-on-error is enabled in the arguments.
|
|
|
if (!completed && arguments.CopyOnError) {
|
|
|
- cmsys::Status copied =
|
|
|
- cmsys::SystemTools::CopyFileAlways(fileName, newFileName);
|
|
|
+ cmsys::Status copied;
|
|
|
+ if (cmp0205 == cmPolicies::NEW && sourceIsDirectory) {
|
|
|
+ copied = cmsys::SystemTools::CopyADirectory(fileName, newFileName);
|
|
|
+ } else {
|
|
|
+ copied = cmsys::SystemTools::CopyFileAlways(fileName, newFileName);
|
|
|
+ }
|
|
|
+
|
|
|
if (copied) {
|
|
|
completed = true;
|
|
|
} else {
|