MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / WriteSettings

Function WriteSettings

src/common/settings.cpp:123–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123bool 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
154SettingsValue GetSetting(const Settings& settings,
155 const std::string& section,

Callers 2

WriteMethod · 0.85
WriteSettingsFileMethod · 0.85

Calls 7

PathToStringFunction · 0.85
pushKVMethod · 0.80
pushKVEndMethod · 0.80
openMethod · 0.45
emplace_backMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected