Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Hadrons/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 '"
Expand Down
3 changes: 2 additions & 1 deletion Hadrons/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 24 additions & 5 deletions Hadrons/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <Hadrons/Global.hpp>

#include <cstdlib>

using namespace Grid;
using namespace Hadrons;
using namespace std::chrono_literals;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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<mode_t>(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] == '/')
Expand All @@ -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
{
Expand Down
3 changes: 3 additions & 0 deletions Hadrons/Global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <regex>
#include <Grid/Grid.h>
#include <cxxabi.h>
#include <sys/stat.h>

#ifndef SITE_SIZE_TYPE
#define SITE_SIZE_TYPE size_t
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions application-template/par-example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<scheduleFile></scheduleFile>
<!-- save schedule file? (deprecated, use DB) -->
<saveSchedule>false</saveSchedule>
<!-- mode for directories created by Hadrons output helpers (octal) -->
<fileDirMode>755</fileDirMode>
<!-- Resilient IO, reread files after parallel file and try to re-write -->
<!-- them if checksum test fails. parallelWriteMaxRetry is the number -->
<!-- of retry after checksum failure, -1 means no check at all. -->
Expand Down