Load Configure File
| 68 | |
| 69 | // Load Configure File |
| 70 | void Properties::loadConfigureFile(const char *fileName) { |
| 71 | std::lock_guard<std::mutex> lock(mutex_); |
| 72 | if (fileName == nullptr) { |
| 73 | logger_->log_error("Configuration file path for %s is a nullptr!", getName().c_str()); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | properties_file_ = utils::file::getFullPath(utils::file::FileUtils::concat_path(getHome(), fileName)); |
| 78 | |
| 79 | logger_->log_info("Using configuration file to load configuration for %s from %s (located at %s)", |
| 80 | getName().c_str(), fileName, properties_file_); |
| 81 | |
| 82 | std::ifstream file(properties_file_, std::ifstream::in); |
| 83 | if (!file.good()) { |
| 84 | logger_->log_error("load configure file failed %s", properties_file_); |
| 85 | return; |
| 86 | } |
| 87 | properties_.clear(); |
| 88 | for (const auto& line : PropertiesFile{file}) { |
| 89 | properties_[line.getKey()] = {utils::StringUtils::replaceEnvironmentVariables(line.getValue()), false}; |
| 90 | } |
| 91 | dirty_ = false; |
| 92 | } |
| 93 | |
| 94 | bool Properties::persistProperties() { |
| 95 | std::lock_guard<std::mutex> lock(mutex_); |
no test coverage detected