Commit dbc94f37 authored by Brad King's avatar Brad King 💬 Committed by Kitware Robot
Browse files

Merge topic 'status-bool-extraction'

a6a0bb15 Status: use the new IsSuccess method
40bbf3fd

 Status: offer an `IsSuccess` method

Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !227
parents b001c54d a6a0bb15
......@@ -55,7 +55,10 @@ public:
#endif
/** Return true on "Success", false otherwise. */
explicit operator bool() const { return this->Kind_ == Kind::Success; }
bool IsSuccess() const { return this->Kind_ == Kind::Success; }
/** Return true on "Success", false otherwise. */
explicit operator bool() const { return this->IsSuccess(); }
/** Return the kind of status. */
Kind GetKind() const { return this->Kind_; }
......
......@@ -2419,7 +2419,7 @@ Status SystemTools::CopyFileAlways(std::string const& source,
if (SystemTools::FileIsDirectory(source)) {
status = SystemTools::MakeDirectory(destination);
if (!status) {
if (!status.IsSuccess()) {
return status;
}
} else {
......@@ -2444,17 +2444,17 @@ Status SystemTools::CopyFileAlways(std::string const& source,
// Create destination directory
if (!destination_dir.empty()) {
status = SystemTools::MakeDirectory(destination_dir);
if (!status) {
if (!status.IsSuccess()) {
return status;
}
}
status = SystemTools::CloneFileContent(source, real_destination);
// if cloning did not succeed, fall back to blockwise copy
if (!status) {
if (!status.IsSuccess()) {
status = SystemTools::CopyFileContentBlockwise(source, real_destination);
}
if (!status) {
if (!status.IsSuccess()) {
return status;
}
}
......@@ -2484,11 +2484,11 @@ Status SystemTools::CopyADirectory(std::string const& source,
Status status;
Directory dir;
status = dir.Load(source);
if (!status) {
if (!status.IsSuccess()) {
return status;
}
status = SystemTools::MakeDirectory(destination);
if (!status) {
if (!status.IsSuccess()) {
return status;
}
......@@ -2503,12 +2503,12 @@ Status SystemTools::CopyADirectory(std::string const& source,
fullDestPath += "/";
fullDestPath += dir.GetFile(static_cast<unsigned long>(fileNum));
status = SystemTools::CopyADirectory(fullPath, fullDestPath, always);
if (!status) {
if (!status.IsSuccess()) {
return status;
}
} else {
status = SystemTools::CopyAFile(fullPath, destination, always);
if (!status) {
if (!status.IsSuccess()) {
return status;
}
}
......@@ -2660,7 +2660,7 @@ Status SystemTools::RemoveADirectory(std::string const& source)
Status status;
Directory dir;
status = dir.Load(source);
if (!status) {
if (!status.IsSuccess()) {
return status;
}
......@@ -2674,12 +2674,12 @@ Status SystemTools::RemoveADirectory(std::string const& source)
if (SystemTools::FileIsDirectory(fullPath) &&
!SystemTools::FileIsSymlink(fullPath)) {
status = SystemTools::RemoveADirectory(fullPath);
if (!status) {
if (!status.IsSuccess()) {
return status;
}
} else {
status = SystemTools::RemoveFile(fullPath);
if (!status) {
if (!status.IsSuccess()) {
return status;
}
}
......@@ -3143,7 +3143,7 @@ Status SystemTools::ReadSymlink(std::string const& newName,
status = Status::Windows_GetLastError();
}
CloseHandle(hFile);
if (!status) {
if (!status.IsSuccess()) {
return status;
}
PREPARSE_DATA_BUFFER data =
......
......@@ -122,7 +122,7 @@ int _copyDirectoryTest()
}
const Status copysuccess = SystemTools::CopyADirectory(source, destination);
const bool destinationexists = SystemTools::PathExists(destination);
if (copysuccess) {
if (copysuccess.IsSuccess()) {
std::cerr << "CopyADirectory should have returned false" << std::endl;
SystemTools::RemoveADirectory(destination);
return 3;
......
......@@ -31,6 +31,10 @@ int testStatus(int, char* [])
std::cerr << "Status Success constructor does not produce Success\n";
res = false;
}
if (!status.IsSuccess()) {
std::cerr << "Status Success gives false IsSuccess\n";
res = false;
}
if (!status) {
std::cerr << "Status Success kind is not true\n";
res = false;
......@@ -55,6 +59,10 @@ int testStatus(int, char* [])
std::cerr << "Status POSIX constructor does not produce POSIX\n";
res = false;
}
if (status.IsSuccess()) {
std::cerr << "Status POSIX gives true IsSuccess\n";
res = false;
}
if (status) {
std::cerr << "Status POSIX kind is not false\n";
res = false;
......@@ -87,6 +95,10 @@ int testStatus(int, char* [])
std::cerr << "Status Windows constructor does not produce Windows\n";
res = false;
}
if (status.IsSuccess()) {
std::cerr << "Status Windows gives true IsSuccess\n";
res = false;
}
if (status) {
std::cerr << "Status Windows kind is not false\n";
res = false;
......
......@@ -436,7 +436,7 @@ static bool CheckFileOperations()
if (symlinkStatus.GetWindows() != ERROR_PRIVILEGE_NOT_HELD)
#endif
{
if (!symlinkStatus) {
if (!symlinkStatus.IsSuccess()) {
std::cerr << "CreateSymlink for: " << testBadSymlink << " -> "
<< testBadSymlinkTgt
<< " failed: " << symlinkStatus.GetString() << std::endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment