| 121 | } |
| 122 | |
| 123 | bool WriteSettings(const fs::path& path, |
| 124 | const std::map<std::string, SettingsValue>& values, |
| 125 | std::vector<std::string>& errors) |
| 126 | { |
| 127 | SettingsValue out(SettingsValue::VOBJ); |
| 128 | // Add auto-generated warning comment |
| 129 | out.pushKV(SETTINGS_WARN_MSG_KEY, strprintf("This file is automatically generated and updated by %s. Please do not edit this file while the node " |
| 130 | "is running, as any changes might be ignored or overwritten.", CLIENT_NAME)); |
| 131 | // Push settings values |
| 132 | for (const auto& value : values) { |
| 133 | out.pushKVEnd(value.first, value.second); |
| 134 | } |
| 135 | std::ofstream file; |
| 136 | file.open(path.std_path()); |
| 137 | if (file.fail()) { |
| 138 | errors.emplace_back(strprintf("Error: Unable to open settings file %s for writing", fs::PathToString(path))); |
| 139 | return false; |
| 140 | } |
| 141 | file << out.write(/* prettyIndent= */ 4, /* indentLevel= */ 1) << std::endl; |
| 142 | if (file.fail()) { |
| 143 | errors.emplace_back(strprintf("Error: Unable to write settings file %s", fs::PathToString(path))); |
| 144 | return false; |
| 145 | } |
| 146 | file.close(); |
| 147 | if (file.fail()) { |
| 148 | errors.emplace_back(strprintf("Error: Unable to close settings file %s", fs::PathToString(path))); |
| 149 | return false; |
| 150 | } |
| 151 | return true; |
| 152 | } |
| 153 | |
| 154 | SettingsValue GetSetting(const Settings& settings, |
| 155 | const std::string& section, |
no test coverage detected