ensure subdirs exist
This commit is contained in:
parent
e9dfb505f2
commit
7e780d647a
|
@ -1,6 +1,7 @@
|
|||
#include "./testutils.h"
|
||||
|
||||
#include "../application/failure.h"
|
||||
#include "../conversion/stringconversion.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
@ -11,6 +12,7 @@
|
|||
|
||||
using namespace std;
|
||||
using namespace ApplicationUtilities;
|
||||
using namespace ConversionUtilities;
|
||||
|
||||
namespace TestUtilities {
|
||||
|
||||
|
@ -158,6 +160,25 @@ string TestApplication::workingCopyPath(const string &name) const
|
|||
}
|
||||
}
|
||||
|
||||
// ensure subdirectory exists
|
||||
const auto parts = splitString<vector<string> >(name, string("/"), EmptyPartsTreat::Omit);
|
||||
if(!parts.empty()) {
|
||||
string currentLevel = m_workingDir;
|
||||
for(auto i = parts.cbegin(), end = parts.end() - 1; i != end; ++i) {
|
||||
if(stat((currentLevel += *i).c_str(), ¤tStat) || !S_ISDIR(currentStat.st_mode)) {
|
||||
|
||||
if(mkdir(currentLevel.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
|
||||
cerr << "Unable to create working copy for \"" << name << "\": can't create working directory." << endl;
|
||||
return string();
|
||||
}
|
||||
if(currentLevel.back() != '/') {
|
||||
currentLevel += '/';
|
||||
}
|
||||
currentLevel += *i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copy file
|
||||
try {
|
||||
origFile.open(testFilePath(name), ios_base::in | ios_base::binary);
|
||||
|
|
Loading…
Reference in New Issue