diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index 3cff940f0..2290394ba 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -505,7 +505,7 @@ namespace Utils std::string removeCommonPath(const std::string& _path, const std::string& _common, bool& _contains) { - std::string path = getGenericPath(_path); + std::string path = getGenericPath(_path); std::string common = isDirectory(_common) ? getGenericPath(_common) : getParent(_common); @@ -676,6 +676,25 @@ namespace Utils #endif } + bool removeDirectory(const std::string& path) + { + if (getDirContent(path).size() != 0) { + LOG(LogError) << "Couldn't delete directory as it's not empty"; + LOG(LogError) << path; + return false; + } + #if defined(_WIN64) + if (_wrmdir(Utils::String::stringToWideString(path).c_str()) == 0) { + #else + if (rmdir(path.c_str()) != 0) { + #endif + LOG(LogError) << "Couldn't delete directory, permission problems?"; + LOG(LogError) << path; + return false; + } + return true; + } + bool createDirectory(const std::string& _path) { std::string path = getGenericPath(_path); diff --git a/es-core/src/utils/FileSystemUtil.h b/es-core/src/utils/FileSystemUtil.h index a11c1e4a9..07459cdd5 100644 --- a/es-core/src/utils/FileSystemUtil.h +++ b/es-core/src/utils/FileSystemUtil.h @@ -53,6 +53,7 @@ namespace Utils bool renameFile(const std::string& _source_path, const std::string& _destination_path, bool _overwrite); bool removeFile(const std::string& _path); + bool removeDirectory(const std::string& path); bool createDirectory(const std::string& _path); bool exists(const std::string& _path);