Commit 2446b205 authored by Brad King's avatar Brad King
Browse files

SystemTools: Return Status from MakeDirectory

parent ab198a22
......@@ -882,21 +882,24 @@ FILE* SystemTools::Fopen(const std::string& file, const char* mode)
#endif
}
bool SystemTools::MakeDirectory(const char* path, const mode_t* mode)
Status SystemTools::MakeDirectory(const char* path, const mode_t* mode)
{
if (!path) {
return false;
return Status::POSIX(EINVAL);
}
return SystemTools::MakeDirectory(std::string(path), mode);
}
bool SystemTools::MakeDirectory(const std::string& path, const mode_t* mode)
Status SystemTools::MakeDirectory(std::string const& path, const mode_t* mode)
{
if (SystemTools::PathExists(path)) {
return SystemTools::FileIsDirectory(path);
}
if (path.empty()) {
return false;
return Status::POSIX(EINVAL);
}
if (SystemTools::PathExists(path)) {
if (SystemTools::FileIsDirectory(path)) {
return Status::Success();
}
return Status::POSIX(EEXIST);
}
std::string dir = path;
SystemTools::ConvertToUnixSlashes(dir);
......@@ -914,15 +917,11 @@ bool SystemTools::MakeDirectory(const std::string& path, const mode_t* mode)
++pos;
}
topdir = dir;
if (Mkdir(topdir, mode) != 0) {
// if it is some other error besides directory exists
// then return false
if (errno != EEXIST) {
return false;
}
if (Mkdir(topdir, mode) != 0 && errno != EEXIST) {
return Status::POSIX_errno();
}
return true;
return Status::Success();
}
// replace replace with with as many times as it shows up in source.
......
......@@ -554,9 +554,9 @@ public:
* can make a full path even if none of the directories existed
* prior to calling this function.
*/
static bool MakeDirectory(const char* path, const mode_t* mode = nullptr);
static bool MakeDirectory(const std::string& path,
const mode_t* mode = nullptr);
static Status MakeDirectory(const char* path, const mode_t* mode = nullptr);
static Status MakeDirectory(std::string const& path,
const mode_t* mode = nullptr);
/**
* Copy the source file to the destination file only
......
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