aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-09-05 17:12:35 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-09-05 17:12:37 +0200
commit91e07cc50db675b97fee324a8a293bc6b353d991 (patch)
treee19061570653e86402bf55cc7809101f3aaf4f73 /src
parent6490a3ef6c4c6525d169818d18a99050f780c5b7 (diff)
parent2b071265c37da22f15769945fd159b50a14792a3 (diff)
Merge bitcoin/bitcoin#22591: Util: error if settings json exists, but is unreadable
2b071265c37da22f15769945fd159b50a14792a3 error if settings.json exists, but is unreadable (Tyler Chambers) Pull request description: If settings.json exists, but is unreadable, we should error instead of overwriting. Fixes #22571 ACKs for top commit: Zero-1729: tACK 2b071265c37da22f15769945fd159b50a14792a3 ShaMan239: tACK 2b071265c37da22f15769945fd159b50a14792a3 prayank23: tACK https://github.com/bitcoin/bitcoin/pull/22591/commits/2b071265c37da22f15769945fd159b50a14792a3 ryanofsky: Code review ACK 2b071265c37da22f15769945fd159b50a14792a3. Thanks for the fix! Note that PR https://github.com/bitcoin-core/gui/pull/379 will change the appearance of dialogs shown in screenshots above. So it could be interesting to test the two PRs together (but current testing seems more than sufficient) theStack: ACK 2b071265c37da22f15769945fd159b50a14792a3 📁 Tree-SHA512: 6f7f96ce8a13213d0335198a2245d127264495c877105058d1503252435915b332a6e55068ac21088f4c0c017d564689f4956213328d5bdee81d73711efc5511
Diffstat (limited to 'src')
-rw-r--r--src/util/settings.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/util/settings.cpp b/src/util/settings.cpp
index b92b1d30c3..846b34089d 100644
--- a/src/util/settings.cpp
+++ b/src/util/settings.cpp
@@ -60,9 +60,15 @@ bool ReadSettings(const fs::path& path, std::map<std::string, SettingsValue>& va
values.clear();
errors.clear();
+ // Ok for file to not exist
+ if (!fs::exists(path)) return true;
+
fsbridge::ifstream file;
file.open(path);
- if (!file.is_open()) return true; // Ok for file not to exist.
+ if (!file.is_open()) {
+ errors.emplace_back(strprintf("%s. Please check permissions.", path.string()));
+ return false;
+ }
SettingsValue in;
if (!in.read(std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()})) {