Merge topic 'cmake-E-copy-system-errors'

fb7a904e90 cmcmd: report system errors on more filesystem operations
4795cb6550 Merge branch 'upstream-KWSys' into cmake-E-copy-system-errors
dc8cc945ee KWSys 2025-11-12 (1139f8a0)

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11401
This commit is contained in:
Brad King
2025-11-12 16:59:24 +00:00
committed by Kitware Robot
10 changed files with 32 additions and 43 deletions
-14
View File
@@ -1646,20 +1646,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)
{
-9
View File
@@ -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
View File
@@ -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;
}
}
+2 -2
View File
@@ -184,7 +184,7 @@ Status Directory::Load(std::string const& name, std::string* errorMessage)
delete[] buf;
if (srchHandle == INVALID_HANDLE_VALUE) {
Status status = Status::POSIX_errno();
Status status = Status::Windows_GetLastError();
if (errorMessage) {
*errorMessage = status.GetString();
}
@@ -198,7 +198,7 @@ Status Directory::Load(std::string const& name, std::string* errorMessage)
} while (FindNextFileW(srchHandle, &data));
this->Internal->Path = name;
if (!FindClose(srchHandle)) {
Status status = Status::POSIX_errno();
Status status = Status::Windows_GetLastError();
if (errorMessage) {
*errorMessage = status.GetString();
}
+1 -1
View File
@@ -2273,7 +2273,7 @@ SystemTools::CopyStatus SystemTools::CopyFileIfNewer(
// source and destination are files so do a copy if source is newer
// Check if source file exists first
if (!SystemTools::FileExists(source)) {
return CopyStatus{ Status::POSIX_errno(), CopyStatus::SourcePath };
return CopyStatus{ Status::POSIX(ENOENT), CopyStatus::SourcePath };
}
// If destination doesn't exist, always copy
if (!SystemTools::FileExists(destination)) {
@@ -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$