diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index a02870a6e..bacc3a631 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -733,6 +733,40 @@ namespace Utils #endif } + bool createEmptyFile(const std::string& path) + { + if (exists(path)) { +#if defined(_WIN64) + LOG(LogError) << "Couldn't create target file \"" + << Utils::String::replace(path, "/", "\\") + << "\" as it already exists"; + return false; + } + + std::ofstream targetFile {Utils::String::stringToWideString(path).c_str(), + std::ios::binary}; + if (targetFile.fail()) { + LOG(LogError) << "Couldn't create target file \"" + << Utils::String::replace(path, "/", "\\") +#else + LOG(LogError) << "Couldn't create target file \"" << path + << "\" as it already exists"; + return false; + } + + std::ofstream targetFile {path, std::ios::binary}; + if (targetFile.fail()) { + LOG(LogError) << "Couldn't create target file \"" << path +#endif + << "\", permission problems?"; + targetFile.close(); + return false; + } + + targetFile.close(); + return true; + } + bool removeFile(const std::string& path) { const std::string& genericPath {getGenericPath(path)}; diff --git a/es-core/src/utils/FileSystemUtil.h b/es-core/src/utils/FileSystemUtil.h index 8fde17040..206ada0df 100644 --- a/es-core/src/utils/FileSystemUtil.h +++ b/es-core/src/utils/FileSystemUtil.h @@ -58,6 +58,7 @@ namespace Utils bool renameFile(const std::string& sourcePath, const std::string& destinationPath, bool overwrite); + bool createEmptyFile(const std::string& path); bool removeFile(const std::string& path); bool removeDirectory(const std::string& path); bool createDirectory(const std::string& path);