Browse Source

Tests: PityTest11 - create dirs

LIB-11
heck 4 years ago
parent
commit
8aa9a8136d
  1. 4
      test/pitytest11/src/PityUnit.hh
  2. 47
      test/pitytest11/src/PityUnit.hxx

4
test/pitytest11/src/PityUnit.hh

@ -51,6 +51,7 @@ namespace pEp {
// Main funcs
void _init() const;
void run() const;
std::string to_string(bool recursive = true, int indent = 0) const;
static std::string to_string(const ExecutionMode& emode);
@ -88,6 +89,9 @@ namespace pEp {
std::string _status_string(const std::string& msg) const;
// TODO
void _ensureDir(const std::string& path) const;
void _recreateDir(const std::string& path ) const;
void _data_dir_delete();
void _data_dir_create();
void _data_dir_recreate();

47
test/pitytest11/src/PityUnit.hxx

@ -20,11 +20,11 @@ using namespace pEp::Adapter::pEpLog;
namespace pEp {
namespace PityTest11 {
template<class T>
std::string PityUnit<T>::_global_root_dir = "./pitytest";
std::string PityUnit<T>::_global_root_dir = "./pitytest_data/";
template<class T>
bool PityUnit<T>::debug_log_enabled = false;
// PUBLIC CONCSTRUCTORS / FACTORY -----------------------------------------------------------
// CONCSTRUCTORS
template<class T>
PityUnit<T>::PityUnit(
PityUnit* const parent,
@ -145,10 +145,23 @@ namespace pEp {
return PityUnit::_global_root_dir;
}
template<class T>
void PityUnit<T>::_init() const
{
_ensureDir(getGlobalRootDir());
_recreateDir(processDir());
if (!_children.empty()) {
for (const std::pair<std::string, PityUnit<T>&> child : _children) {
_recreateDir(child.second.processDir());
}
}
}
template<class T>
void PityUnit<T>::run() const
{
pEpLogClass("called");
_init();
// caller is never nullptr if called by another PityUnit
if (_isRootNode()) {
logH1("Starting PityUnit from node: " + getNodePathShort());
@ -296,7 +309,8 @@ namespace pEp {
int status;
pid_t pid;
while ((pid = wait(&status)) > 0) {
pEpLogClass("process[" + std::to_string((int)pid) +
pEpLogClass(
"process[" + std::to_string((int)pid) +
"] terminated with status: " + std::to_string(status));
}
}
@ -375,6 +389,31 @@ namespace pEp {
return ret;
}
template<class T>
void PityUnit<T>::_ensureDir(const std::string& path) const
{
if (!Utils::path_exists(path)) {
log("creating dir:" + path);
Utils::dir_create(path);
}
}
template<class T>
void PityUnit<T>::_recreateDir(const std::string& path) const
{
if (Utils::path_exists(path)) {
try {
log("deleting dir:" + path);
Utils::path_delete_all(path);
} catch (const std::exception& e) {
log("PityUnit: - could not delete data dir: " + getGlobalRootDir());
}
}
log("creating dir:" + path);
Utils::dir_create(path);
}
template<class T>
void PityUnit<T>::_data_dir_create()
{
@ -386,7 +425,7 @@ namespace pEp {
void PityUnit<T>::_data_dir_delete()
{
try {
Utils::path_delete_all(getGlobalRootDir());
// Utils::path_delete_all(getGlobalRootDir());
} catch (const std::exception& e) {
log("DistTest: - could not delete data dir: " + getGlobalRootDir());
}

Loading…
Cancel
Save