Commit c5a99e59 authored by Brad King's avatar Brad King
Browse files

SystemTools: Return Status from GetPermissions and SetPermissions

parent 955e7c1e
......@@ -2379,7 +2379,7 @@ bool SystemTools::CopyFileAlways(const std::string& source,
const std::string& destination)
{
mode_t perm = 0;
bool perms = SystemTools::GetPermissions(source, perm);
Status perms = SystemTools::GetPermissions(source, perm);
std::string real_destination = destination;
if (SystemTools::FileIsDirectory(source)) {
......@@ -4098,21 +4098,21 @@ int SystemTools::GetTerminalWidth()
return width;
}
bool SystemTools::GetPermissions(const char* file, mode_t& mode)
Status SystemTools::GetPermissions(const char* file, mode_t& mode)
{
if (!file) {
return false;
return Status::POSIX(EINVAL);
}
return SystemTools::GetPermissions(std::string(file), mode);
}
bool SystemTools::GetPermissions(const std::string& file, mode_t& mode)
Status SystemTools::GetPermissions(std::string const& file, mode_t& mode)
{
#if defined(_WIN32)
DWORD attr =
GetFileAttributesW(Encoding::ToWindowsExtendedPath(file).c_str());
if (attr == INVALID_FILE_ATTRIBUTES) {
return false;
return Status::Windows_GetLastError();
}
if ((attr & FILE_ATTRIBUTE_READONLY) != 0) {
mode = (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6));
......@@ -4135,27 +4135,27 @@ bool SystemTools::GetPermissions(const std::string& file, mode_t& mode)
#else
struct stat st;
if (stat(file.c_str(), &st) < 0) {
return false;
return Status::POSIX_errno();
}
mode = st.st_mode;
#endif
return true;
return Status::Success();
}
bool SystemTools::SetPermissions(const char* file, mode_t mode,
bool honor_umask)
Status SystemTools::SetPermissions(const char* file, mode_t mode,
bool honor_umask)
{
if (!file) {
return false;
return Status::POSIX(EINVAL);
}
return SystemTools::SetPermissions(std::string(file), mode, honor_umask);
}
bool SystemTools::SetPermissions(const std::string& file, mode_t mode,
bool honor_umask)
Status SystemTools::SetPermissions(std::string const& file, mode_t mode,
bool honor_umask)
{
if (!SystemTools::PathExists(file)) {
return false;
return Status::POSIX(ENOENT);
}
if (honor_umask) {
mode_t currentMask = umask(0);
......@@ -4168,10 +4168,10 @@ bool SystemTools::SetPermissions(const std::string& file, mode_t mode,
if (chmod(file.c_str(), mode) < 0)
#endif
{
return false;
return Status::POSIX_errno();
}
return true;
return Status::Success();
}
std::string SystemTools::GetParentDirectory(const std::string& fileOrDir)
......
......@@ -777,12 +777,12 @@ public:
* WARNING: A non-thread-safe method is currently used to get the umask
* if a honor_umask parameter is set to true.
*/
static bool GetPermissions(const char* file, mode_t& mode);
static bool GetPermissions(const std::string& file, mode_t& mode);
static bool SetPermissions(const char* file, mode_t mode,
bool honor_umask = false);
static bool SetPermissions(const std::string& file, mode_t mode,
bool honor_umask = false);
static Status GetPermissions(const char* file, mode_t& mode);
static Status GetPermissions(std::string const& file, mode_t& mode);
static Status SetPermissions(const char* file, mode_t mode,
bool honor_umask = false);
static Status SetPermissions(std::string const& file, mode_t mode,
bool honor_umask = false);
/** -----------------------------------------------------------------
* Time Manipulation Routines
......
Markdown is supported
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