mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-19 19:43:23 +08:00
Source: Remove redundant FileIsSymlink checks
Replace `FileExists || FileIsSymlink` with `PathExists`. The latter does not resolve symlinks, so this is OK for use with broken symlinks, files, and directories.
This commit is contained in:
@@ -3020,8 +3020,7 @@ bool HandleCreateLinkCommand(std::vector<std::string> const& args,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the new file already exists and remove it.
|
// Check if the new file already exists and remove it.
|
||||||
if ((cmSystemTools::FileExists(newFileName) ||
|
if (cmSystemTools::PathExists(newFileName) &&
|
||||||
cmSystemTools::FileIsSymlink(newFileName)) &&
|
|
||||||
!cmSystemTools::RemoveFile(newFileName)) {
|
!cmSystemTools::RemoveFile(newFileName)) {
|
||||||
std::ostringstream e;
|
std::ostringstream e;
|
||||||
e << "Failed to create link '" << newFileName
|
e << "Failed to create link '" << newFileName
|
||||||
|
@@ -3264,7 +3264,7 @@ int cmake::CheckBuildSystem()
|
|||||||
// If any byproduct of makefile generation is missing we must re-run.
|
// If any byproduct of makefile generation is missing we must re-run.
|
||||||
cmList products{ mf.GetDefinition("CMAKE_MAKEFILE_PRODUCTS") };
|
cmList products{ mf.GetDefinition("CMAKE_MAKEFILE_PRODUCTS") };
|
||||||
for (auto const& p : products) {
|
for (auto const& p : products) {
|
||||||
if (!(cmSystemTools::FileExists(p) || cmSystemTools::FileIsSymlink(p))) {
|
if (!cmSystemTools::PathExists(p)) {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
cmSystemTools::Stdout(
|
cmSystemTools::Stdout(
|
||||||
cmStrCat("Re-run cmake, missing byproduct: ", p, '\n'));
|
cmStrCat("Re-run cmake, missing byproduct: ", p, '\n'));
|
||||||
|
@@ -1018,8 +1018,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
|||||||
// Complain if the -f option was not given and
|
// Complain if the -f option was not given and
|
||||||
// either file does not exist or
|
// either file does not exist or
|
||||||
// file could not be removed and still exists
|
// file could not be removed and still exists
|
||||||
bool file_exists_or_forced_remove = cmSystemTools::FileExists(arg) ||
|
bool file_exists_or_forced_remove =
|
||||||
cmSystemTools::FileIsSymlink(arg) || force;
|
cmSystemTools::PathExists(arg) || force;
|
||||||
if (cmSystemTools::FileIsDirectory(arg)) {
|
if (cmSystemTools::FileIsDirectory(arg)) {
|
||||||
if (!cmRemoveDirectory(arg, recursive)) {
|
if (!cmRemoveDirectory(arg, recursive)) {
|
||||||
return_value = 1;
|
return_value = 1;
|
||||||
@@ -1239,8 +1239,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
|||||||
// supporting them.
|
// supporting them.
|
||||||
if (args[1] == "create_symlink" && args.size() == 4) {
|
if (args[1] == "create_symlink" && args.size() == 4) {
|
||||||
std::string const& destinationFileName = args[3];
|
std::string const& destinationFileName = args[3];
|
||||||
if ((cmSystemTools::FileExists(destinationFileName) ||
|
if (cmSystemTools::PathExists(destinationFileName) &&
|
||||||
cmSystemTools::FileIsSymlink(destinationFileName)) &&
|
|
||||||
!cmSystemTools::RemoveFile(destinationFileName)) {
|
!cmSystemTools::RemoveFile(destinationFileName)) {
|
||||||
std::string emsg = cmSystemTools::GetLastSystemError();
|
std::string emsg = cmSystemTools::GetLastSystemError();
|
||||||
std::cerr << "failed to create symbolic link '" << destinationFileName
|
std::cerr << "failed to create symbolic link '" << destinationFileName
|
||||||
@@ -1266,8 +1265,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cmSystemTools::FileExists(destinationFileName) ||
|
if (cmSystemTools::PathExists(destinationFileName) &&
|
||||||
cmSystemTools::FileIsSymlink(destinationFileName)) &&
|
|
||||||
!cmSystemTools::RemoveFile(destinationFileName)) {
|
!cmSystemTools::RemoveFile(destinationFileName)) {
|
||||||
std::string emsg = cmSystemTools::GetLastSystemError();
|
std::string emsg = cmSystemTools::GetLastSystemError();
|
||||||
std::cerr << "failed to create hard link '" << destinationFileName
|
std::cerr << "failed to create hard link '" << destinationFileName
|
||||||
@@ -1750,7 +1748,7 @@ int cmcmd::SymlinkExecutable(std::vector<std::string> const& args)
|
|||||||
cmsys::Status cmcmd::SymlinkInternal(std::string const& file,
|
cmsys::Status cmcmd::SymlinkInternal(std::string const& file,
|
||||||
std::string const& link)
|
std::string const& link)
|
||||||
{
|
{
|
||||||
if (cmSystemTools::FileExists(link) || cmSystemTools::FileIsSymlink(link)) {
|
if (cmSystemTools::PathExists(link)) {
|
||||||
cmSystemTools::RemoveFile(link);
|
cmSystemTools::RemoveFile(link);
|
||||||
}
|
}
|
||||||
std::string linktext = cmSystemTools::GetFilenameName(file);
|
std::string linktext = cmSystemTools::GetFilenameName(file);
|
||||||
|
Reference in New Issue
Block a user