mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-09 23:59:53 -05:00
cmcmd: report system errors on more filesystem operations
Print the system error message in case of failure when calling `CopyFileAlways`, `CopyFileIfDifferent`, `CopyFileIfNewer`, `CopyADirectory` and `MakeDirectory`. Remove unnecessary `cmSystemTools` wrappers for `CopyFileIfNewer` and `CopyADirectory`. Fixes: #18276
This commit is contained in:
committed by
Brad King
parent
4795cb6550
commit
fb7a904e90
@@ -1645,20 +1645,6 @@ cmSystemTools::CopyResult cmSystemTools::CopySingleFile(
|
||||
return CopyResult::Success;
|
||||
}
|
||||
|
||||
bool cmSystemTools::CopyFileIfNewer(std::string const& source,
|
||||
std::string const& destination)
|
||||
{
|
||||
return cmsys::SystemTools::CopyFileIfNewer(source, destination).IsSuccess();
|
||||
}
|
||||
|
||||
bool cmSystemTools::CopyADirectory(std::string const& source,
|
||||
std::string const& destination,
|
||||
CopyWhen when)
|
||||
{
|
||||
return cmsys::SystemTools::CopyADirectory(source, destination, when)
|
||||
.IsSuccess();
|
||||
}
|
||||
|
||||
bool cmSystemTools::RenameFile(std::string const& oldname,
|
||||
std::string const& newname)
|
||||
{
|
||||
|
||||
@@ -205,15 +205,6 @@ public:
|
||||
CopyInputRecent inputRecent,
|
||||
std::string* err = nullptr);
|
||||
|
||||
/** Copy a file if it is newer than the destination. */
|
||||
static bool CopyFileIfNewer(std::string const& source,
|
||||
std::string const& destination);
|
||||
|
||||
/** Copy directory contents with specified copy behavior. */
|
||||
static bool CopyADirectory(std::string const& source,
|
||||
std::string const& destination,
|
||||
CopyWhen when = CopyWhen::Always);
|
||||
|
||||
enum class Replace
|
||||
{
|
||||
Yes,
|
||||
|
||||
+22
-10
@@ -749,9 +749,11 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
// If error occurs we want to continue copying next files.
|
||||
bool return_value = false;
|
||||
for (auto const& file : files) {
|
||||
if (!cmsys::SystemTools::CopyFileAlways(file, *targetArg)) {
|
||||
cmsys::SystemTools::CopyStatus const status =
|
||||
cmSystemTools::CopyFileAlways(file, *targetArg);
|
||||
if (!status) {
|
||||
std::cerr << "Error copying file \"" << file << "\" to \""
|
||||
<< *targetArg << "\".\n";
|
||||
<< *targetArg << "\": " << status.GetString() << '\n';
|
||||
return_value = true;
|
||||
}
|
||||
}
|
||||
@@ -771,9 +773,12 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
// If error occurs we want to continue copying next files.
|
||||
bool return_value = false;
|
||||
for (auto const& arg : cmMakeRange(args).advance(2).retreat(1)) {
|
||||
if (!cmSystemTools::CopyFileIfDifferent(arg, args.back())) {
|
||||
cmsys::SystemTools::CopyStatus const status =
|
||||
cmSystemTools::CopyFileIfDifferent(arg, args.back());
|
||||
if (!status) {
|
||||
std::cerr << "Error copying file (if different) from \"" << arg
|
||||
<< "\" to \"" << args.back() << "\".\n";
|
||||
<< "\" to \"" << args.back()
|
||||
<< "\": " << status.GetString() << '\n';
|
||||
return_value = true;
|
||||
}
|
||||
}
|
||||
@@ -793,9 +798,12 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
// If error occurs we want to continue copying next files.
|
||||
bool return_value = false;
|
||||
for (auto const& arg : cmMakeRange(args).advance(2).retreat(1)) {
|
||||
if (!cmSystemTools::CopyFileIfNewer(arg, args.back())) {
|
||||
cmsys::SystemTools::CopyStatus const status =
|
||||
cmSystemTools::CopyFileIfNewer(arg, args.back());
|
||||
if (!status) {
|
||||
std::cerr << "Error copying file (if newer) from \"" << arg
|
||||
<< "\" to \"" << args.back() << "\".\n";
|
||||
<< "\" to \"" << args.back()
|
||||
<< "\": " << status.GetString() << '\n';
|
||||
return_value = true;
|
||||
}
|
||||
}
|
||||
@@ -818,9 +826,11 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
}
|
||||
|
||||
for (auto const& arg : cmMakeRange(args).advance(2).retreat(1)) {
|
||||
if (!cmSystemTools::CopyADirectory(arg, args.back(), when)) {
|
||||
cmsys::Status const status =
|
||||
cmSystemTools::CopyADirectory(arg, args.back(), when);
|
||||
if (!status) {
|
||||
std::cerr << "Error copying directory from \"" << arg << "\" to \""
|
||||
<< args.back() << "\".\n";
|
||||
<< args.back() << "\": " << status.GetString() << '\n';
|
||||
return_value = true;
|
||||
}
|
||||
}
|
||||
@@ -1023,8 +1033,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
// If an error occurs, we want to continue making directories.
|
||||
bool return_value = false;
|
||||
for (auto const& arg : cmMakeRange(args).advance(2)) {
|
||||
if (!cmSystemTools::MakeDirectory(arg)) {
|
||||
std::cerr << "Error creating directory \"" << arg << "\".\n";
|
||||
cmsys::Status const status = cmSystemTools::MakeDirectory(arg);
|
||||
if (!status) {
|
||||
std::cerr << "Error creating directory \"" << arg
|
||||
<< "\": " << status.GetString() << '\n';
|
||||
return_value = true;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,3 +1,3 @@
|
||||
^Error copying directory from .* to .*file_for_test\.txt\".*
|
||||
Error copying directory from .* to .*file_for_test\.txt\".*
|
||||
Error copying directory from .* to .*file_for_test\.txt\"\.$
|
||||
^Error copying directory from "[^"]+" to "[^"]+file_for_test\.txt": File exists
|
||||
Error copying directory from "[^"]+" to "[^"]+file_for_test\.txt": File exists
|
||||
Error copying directory from "[^"]+" to "[^"]+file_for_test\.txt": File exists$
|
||||
|
||||
@@ -1 +1 @@
|
||||
^Error copying directory from ".+" to ".+"\.$
|
||||
^Error copying directory from "[^"]+" to "[^"]+": (No such file or directory|The system cannot find the path specified\.)$
|
||||
|
||||
@@ -1 +1 @@
|
||||
^Error copying file \(if different\) from ".+" to ".+"\.$
|
||||
^Error copying file \(if different\) from "[^"]+" to "[^"]+": No such file or directory$
|
||||
|
||||
@@ -1 +1 @@
|
||||
^Error copying file \(if newer\) from ".+" to ".+"\.$
|
||||
^Error copying file \(if newer\) from "[^"]+" to "[^"]+": No such file or directory$
|
||||
|
||||
@@ -1 +1 @@
|
||||
^Error creating directory .*file_for_test\.txt\"\.$
|
||||
^Error creating directory "[^"]+file_for_test\.txt": File exists$
|
||||
|
||||
Reference in New Issue
Block a user