20 #include "createdir.h" 21 #include "softwarecontainererror.h" 27 CreateDir::~CreateDir()
31 while (!m_rollbackCleaners.empty()) {
32 auto cuHandler = m_rollbackCleaners.back();
33 m_rollbackCleaners.pop_back();
35 if (!cuHandler.clean()) {
41 log_error() <<
"One or more cleanup handlers returned error status, please check the log";
46 bool CreateDir::createParentDirectory(
const std::string path)
48 log_debug() <<
"Creating parent directories for " << path;
49 std::string parent = parentPath(path);
52 log_error() <<
"Could not create directory " << parent;
65 if(!createParentDirectory(path)) {
66 log_error() <<
"Couldn't create parent directory for " << path;
70 if (mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) == -1) {
71 log_error() <<
"Could not create directory " << path <<
": " << strerror(errno);
75 if (!pathInList(path)){
76 m_rollbackCleaners.emplace_back(path);
83 char *dir =
const_cast<char*
>(templ.c_str());
86 std::string message =
"Failed to create directory from template: " + std::string(strerror(errno));
87 log_warning() << message;
91 m_rollbackCleaners.emplace_back(std::string(dir));
92 return std::string(dir);
95 bool CreateDir::pathInList(
const std::string path)
97 for (
auto &element : m_rollbackCleaners) {
98 if (element.queryName() == path) {
bool createDirectory(const std::string path)
createDirectory creates a directory according to given path.
bool isDirectory(const std::string &path)
isDirectory Check if path is a directory
std::string createTempDirectoryFromTemplate(std::string templatePath)
createTempDirectoryFromTemplate creates a uniquely named directory according to templatePath.
Developers guide to adding a config item: