Commit 9e0b4d1a authored by Domen Vrankar's avatar Domen Vrankar

SystemTools: set default MakeDirectory permissions mode

MakeDirectory can create an entire directory structure
so it's convenient that we can set the default directory
permissions for directories that did not exist beforehand.
parent fc4d55ba
......@@ -751,15 +751,15 @@ FILE* SystemTools::Fopen(const std::string& file, const char* mode)
#endif
}
bool SystemTools::MakeDirectory(const char* path)
bool SystemTools::MakeDirectory(const char* path, const mode_t* mode)
{
if (!path) {
return false;
}
return SystemTools::MakeDirectory(std::string(path));
return SystemTools::MakeDirectory(std::string(path), mode);
}
bool SystemTools::MakeDirectory(const std::string& path)
bool SystemTools::MakeDirectory(const std::string& path, const mode_t* mode)
{
if (SystemTools::PathExists(path)) {
return SystemTools::FileIsDirectory(path);
......@@ -774,8 +774,12 @@ bool SystemTools::MakeDirectory(const std::string& path)
std::string topdir;
while ((pos = dir.find('/', pos)) != std::string::npos) {
topdir = dir.substr(0, pos);
Mkdir(topdir);
pos++;
if (Mkdir(topdir) == 0 && mode != 0) {
SystemTools::SetPermissions(topdir, *mode);
}
++pos;
}
topdir = dir;
if (Mkdir(topdir) != 0) {
......@@ -790,7 +794,10 @@ bool SystemTools::MakeDirectory(const std::string& path)
) {
return false;
}
} else if (mode != 0) {
SystemTools::SetPermissions(topdir, *mode);
}
return true;
}
......
......@@ -553,13 +553,20 @@ public:
*/
static FILE* Fopen(const std::string& file, const char* mode);
/**
* Visual C++ does not define mode_t (note that Borland does, however).
*/
#if defined(_MSC_VER)
typedef unsigned short mode_t;
#endif
/**
* Make a new directory if it is not there. This function
* can make a full path even if none of the directories existed
* prior to calling this function.
*/
static bool MakeDirectory(const char* path);
static bool MakeDirectory(const std::string& path);
static bool MakeDirectory(const char* path, const mode_t* mode = 0);
static bool MakeDirectory(const std::string& path, const mode_t* mode = 0);
/**
* Copy the source file to the destination file only
......@@ -749,13 +756,6 @@ public:
*/
static long int CreationTime(const std::string& filename);
/**
* Visual C++ does not define mode_t (note that Borland does, however).
*/
#if defined(_MSC_VER)
typedef unsigned short mode_t;
#endif
/**
* Get and set permissions of the file. If honor_umask is set, the umask
* is queried and applied to the given permissions. Returns false if
......
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