1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-04 19:25:56 +01:00

Hadrons: automatic directory creation fix

This commit is contained in:
Antonin Portelli 2018-04-23 18:45:39 +01:00
parent 2fa2b0e0b1
commit 6764362237
3 changed files with 24 additions and 6 deletions

View File

@ -96,7 +96,7 @@ const std::string Hadrons::resultFileExt = "xml";
// recursive mkdir /////////////////////////////////////////////////////////////
int Hadrons::mkdir(const std::string dirName)
{
if (access(dirName.c_str(), R_OK|W_OK|X_OK))
if (!dirName.empty() and access(dirName.c_str(), R_OK|W_OK|X_OK))
{
mode_t mode755;
char tmp[MAX_PATH_LENGTH];
@ -143,3 +143,18 @@ std::string Hadrons::basename(const std::string &s)
return s;
}
}
std::string Hadrons::dirname(const std::string &s)
{
constexpr char sep = '/';
size_t i = s.rfind(sep, s.length());
if (i != std::string::npos)
{
return s.substr(0, i);
}
else
{
return "";
}
}

View File

@ -191,6 +191,7 @@ name + "." + std::to_string(vm().getTrajectory()) + "." + resultFileExt
#define MAX_PATH_LENGTH 512u
int mkdir(const std::string dirName);
std::string basename(const std::string &s);
std::string dirname(const std::string &s);
// default Schur convention
#ifndef HADRONS_DEFAULT_SCHUR

View File

@ -122,14 +122,16 @@ MACRO_REDIRECT(__VA_ARGS__, envTmpLat5, envTmpLat4)(__VA_ARGS__)
#define saveResult(ioStem, name, result)\
if (env().getGrid()->IsBoss())\
{\
ResultWriter _writer(RESULT_FILE_NAME(ioStem));\
std::string _basename = basename(ioStem);\
std::string _dirname = dirname(ioStem);\
\
if (!mkdir(_basename))\
if (mkdir(_dirname))\
{\
HADRON_ERROR(Io, "cannot create directory '" + _basename + "'");\
HADRON_ERROR(Io, "cannot create directory '" + _dirname + "'");\
}\
{\
ResultWriter _writer(RESULT_FILE_NAME(ioStem));\
write(_writer, name, result);\
}\
write(_writer, name, result);\
}
/******************************************************************************