mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-08 14:50:10 -06:00
file(CREATE_LINK): Refactor error handling for removal of destination
Avoid relying on global state.
This commit is contained in:
committed by
hanna.rusakovich
parent
0448f646a8
commit
f719a36bc0
@@ -3233,18 +3233,20 @@ bool HandleCreateLinkCommand(std::vector<std::string> const& args,
|
||||
}
|
||||
|
||||
// Check if the new file already exists and remove it.
|
||||
if (cmSystemTools::PathExists(newFileName) &&
|
||||
!cmSystemTools::RemoveFile(newFileName)) {
|
||||
auto err = cmStrCat("Failed to create link '", newFileName,
|
||||
"' because existing path cannot be removed: ",
|
||||
cmSystemTools::GetLastSystemError(), '\n');
|
||||
if (cmSystemTools::PathExists(newFileName)) {
|
||||
cmsys::Status rmStatus = cmSystemTools::RemoveFile(newFileName);
|
||||
if (!rmStatus) {
|
||||
auto 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);
|
||||
return true;
|
||||
if (!arguments.Result.empty()) {
|
||||
status.GetMakefile().AddDefinition(arguments.Result, err);
|
||||
return true;
|
||||
}
|
||||
status.SetError(err);
|
||||
return false;
|
||||
}
|
||||
status.SetError(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Whether the operation completed successfully.
|
||||
|
||||
Reference in New Issue
Block a user