fgerlits commented on code in PR #2069:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2069#discussion_r2547219712
##########
libminifi/src/properties/Properties.cpp:
##########
@@ -173,55 +180,82 @@ void PropertiesImpl::loadConfigureFile(const
std::filesystem::path& configuratio
}
std::error_code ec;
- properties_file_ = std::filesystem::canonical(configuration_file, ec);
+ base_properties_file_ = std::filesystem::canonical(configuration_file, ec);
if (ec.value() != 0) {
logger_->log_warn("Configuration file '{}' does not exist, and it could
not be created", configuration_file);
return;
}
- logger_->log_info("Using configuration file to load configuration for {}
from {} (located at {})",
- getName().c_str(), configuration_file.string(),
properties_file_.string());
+ properties_files_ = { base_properties_file_ };
+
+ const auto extra_properties_files_dir = extra_properties_files_dir_name();
+ std::vector<std::filesystem::path> extra_properties_file_names;
+ if (utils::file::exists(extra_properties_files_dir) &&
utils::file::is_directory(extra_properties_files_dir)) {
+ utils::file::list_dir(extra_properties_files_dir, [&](const
std::filesystem::path&, const std::filesystem::path& file_name) {
+ if (!file_name.string().ends_with(".bak")) {
+ extra_properties_file_names.push_back(file_name);
+ }
+ return true;
+ }, logger_, /* recursive = */ false);
+ }
+ std::ranges::sort(extra_properties_file_names);
+ for (const auto& file_name : extra_properties_file_names) {
+ properties_files_.push_back(extra_properties_files_dir / file_name);
+ }
- std::ifstream file(properties_file_, std::ifstream::in);
- if (!file.good()) {
- logger_->log_error("load configure file failed {}", properties_file_);
- return;
+ logger_->log_info("Using configuration file to load configuration for {}
from {} (located at {})",
+ getName().c_str(), configuration_file.string(),
base_properties_file_.string());
+ if (!extra_properties_file_names.empty()) {
+ auto list_of_files = utils::string::join(", ",
extra_properties_file_names, [](const auto& path) { return path.string(); });
+ logger_->log_info("Also reading configuration from files {} in {}",
list_of_files, extra_properties_files_dir.string());
}
+
properties_.clear();
dirty_ = false;
- for (const auto& line : PropertiesFile{file}) {
- auto key = line.getKey();
- auto persisted_value = line.getValue();
- auto value = utils::string::replaceEnvironmentVariables(persisted_value);
- bool need_to_persist_new_value = false;
- fixValidatedProperty(std::string(prefix) + key, persisted_value, value,
need_to_persist_new_value, *logger_);
- dirty_ = dirty_ || need_to_persist_new_value;
- properties_[key] = {persisted_value, value, need_to_persist_new_value};
+ for (const auto& properties_file : properties_files_) {
+ std::ifstream file(properties_file, std::ifstream::in);
+ if (!file.good()) {
+ logger_->log_error("load configure file failed {}", properties_file);
+ continue;
+ }
+ for (const auto& line : PropertiesFile{file}) {
+ auto key = line.getKey();
+ auto persisted_value = line.getValue();
+ auto value = utils::string::replaceEnvironmentVariables(persisted_value);
+ bool need_to_persist_new_value = false;
+ fixValidatedProperty(std::string(prefix) + key, persisted_value, value,
need_to_persist_new_value, *logger_);
+ dirty_ = dirty_ || need_to_persist_new_value;
+ properties_[key] = {persisted_value, value, need_to_persist_new_value};
+ }
}
Review Comment:
I have refactored `loadConfigureFile` by pulling out two self-contained
sections: edf88de08e2e407a150cf8af8217a8caaa90426a
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]