Browse Source

Tests: PityTest11 - create dirs

master
heck 4 years ago
parent
commit
6dadf32728
  1. 4
      src/PityUnit.hh
  2. 47
      src/PityUnit.hxx

4
src/PityUnit.hh

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

47
src/PityUnit.hxx

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

Loading…
Cancel
Save