diff --git a/SystemTools.cxx b/SystemTools.cxx index a24a3262b7c10900fe3916ca934bd619eb08cb43..72babc31caaa6537734b14a832d1b093eefce123 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -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; } diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index 35bc1b19ba7e10020f06de03d2a97c36fe4a18e5..3d109a88ea4235d8ac6266ab1140bd02a90f8330 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -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