diff --git a/Hadrons/Application.cpp b/Hadrons/Application.cpp index ce3dfbbb..47353770 100644 --- a/Hadrons/Application.cpp +++ b/Hadrons/Application.cpp @@ -98,6 +98,11 @@ Application::Application(const std::string parameterFileName) void Application::setPar(const Application::GlobalPar &par) { par_ = par; + if (par_.fileDirMode.empty()) + { + par_.fileDirMode = "755"; + } + setFileDirMode(par_.fileDirMode); if (!getPar().database.applicationDb.empty()) { LOG(Message) << "Connecting to application database in file '" diff --git a/Hadrons/Application.hpp b/Hadrons/Application.hpp index d0e048d7..39952533 100644 --- a/Hadrons/Application.hpp +++ b/Hadrons/Application.hpp @@ -86,8 +86,9 @@ class Application std::string, graphFile, std::string, scheduleFile, bool, saveSchedule, + std::string, fileDirMode, int, parallelWriteMaxRetry); - GlobalPar(void): parallelWriteMaxRetry{-1}, saveSchedule{false} {} + GlobalPar(void): fileDirMode{"755"}, parallelWriteMaxRetry{-1}, saveSchedule{false} {} }; struct ObjectId: Serializable diff --git a/Hadrons/Global.cpp b/Hadrons/Global.cpp index 2a85c4c8..0a265984 100644 --- a/Hadrons/Global.cpp +++ b/Hadrons/Global.cpp @@ -26,6 +26,8 @@ #include +#include + using namespace Grid; using namespace Hadrons; using namespace std::chrono_literals; @@ -36,6 +38,7 @@ HadronsLogger Hadrons::HadronsLogMessage(1,"Message"); HadronsLogger Hadrons::HadronsLogIterative(1,"Iterative"); HadronsLogger Hadrons::HadronsLogDebug(1,"Debug"); HadronsLogger Hadrons::HadronsLogIRL(1,"IRL"); +mode_t Hadrons::fileDirMode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; void Hadrons::initLogger(void) { @@ -97,17 +100,33 @@ const std::string Hadrons::resultFileExt = "xml"; #endif // recursive mkdir ///////////////////////////////////////////////////////////// +void Hadrons::setFileDirMode(const std::string &mode) +{ + if (mode.empty()) + { + fileDirMode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; + return; + } + + char *end = nullptr; + unsigned long value = std::strtoul(mode.c_str(), &end, 8); + + if ((end == mode.c_str()) or (*end != '\0') or (value > 0777)) + { + HADRONS_ERROR(Definition, "invalid file directory mode '" + mode + "'"); + } + + fileDirMode = static_cast(value); +} + int Hadrons::mkdir(const std::string dirName) { if (!dirName.empty() and access(dirName.c_str(), R_OK|W_OK|X_OK)) { - mode_t mode755; char tmp[MAX_PATH_LENGTH]; char *p = NULL; size_t len; - mode755 = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; - snprintf(tmp, sizeof(tmp), "%s", dirName.c_str()); len = strlen(tmp); if(tmp[len - 1] == '/') @@ -119,12 +138,12 @@ int Hadrons::mkdir(const std::string dirName) if(*p == '/') { *p = 0; - ::mkdir(tmp, mode755); + ::mkdir(tmp, fileDirMode); *p = '/'; } } - return ::mkdir(tmp, mode755); + return ::mkdir(tmp, fileDirMode); } else { diff --git a/Hadrons/Global.hpp b/Hadrons/Global.hpp index e73b2fe2..91c5c0a6 100644 --- a/Hadrons/Global.hpp +++ b/Hadrons/Global.hpp @@ -40,6 +40,7 @@ #include #include #include +#include #ifndef SITE_SIZE_TYPE #define SITE_SIZE_TYPE size_t @@ -295,6 +296,8 @@ typedef XmlWriter ResultWriter; // recursive mkdir #define MAX_PATH_LENGTH 512u +extern mode_t fileDirMode; +void setFileDirMode(const std::string &mode); int mkdir(const std::string dirName); std::string basename(const std::string &s); std::string dirname(const std::string &s); diff --git a/application-template/par-example.xml b/application-template/par-example.xml index 54bec009..4e42658d 100644 --- a/application-template/par-example.xml +++ b/application-template/par-example.xml @@ -49,6 +49,8 @@ false + + 755