From 6ba561dea2f2755cd86d5cc01a23c67cde6fcefd Mon Sep 17 00:00:00 2001 From: Omar Abdul Azeez <49833164+Omar-Abdul-Azeez@users.noreply.github.com> Date: Sun, 13 Aug 2023 00:59:24 +0900 Subject: [PATCH] Fix overwriting feeds.json with an incomplete load of it PR #19444. Closes #19439. --------- Co-authored-by: Vladimir Golovnev --- src/base/rss/rss_session.cpp | 14 +++++++------- src/base/rss/rss_session.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/base/rss/rss_session.cpp b/src/base/rss/rss_session.cpp index 6de5c26d7..ec4959eeb 100644 --- a/src/base/rss/rss_session.cpp +++ b/src/base/rss/rss_session.cpp @@ -271,6 +271,7 @@ void Session::load() if (readResult.error().status == Utils::IO::ReadError::NotExist) { loadLegacy(); + store(); // convert to new format return; } @@ -294,10 +295,11 @@ void Session::load() return; } - loadFolder(jsonDoc.object(), rootFolder()); + if (loadFolder(jsonDoc.object(), rootFolder())) + store(); // convert to updated format } -void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder) +bool Session::loadFolder(const QJsonObject &jsonObj, Folder *folder) { bool updated = false; for (const QString &key : asConst(jsonObj.keys())) @@ -353,7 +355,8 @@ void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder) } else { - loadFolder(valObj, addSubfolder(key, folder)); + if (loadFolder(valObj, addSubfolder(key, folder))) + updated = true; } } else @@ -363,8 +366,7 @@ void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder) } } - if (updated) - store(); // convert to updated format + return updated; } void Session::loadLegacy() @@ -394,8 +396,6 @@ void Session::loadLegacy() addFeed(feedUrl, feedPath); ++i; } - - store(); // convert to new format } void Session::store() diff --git a/src/base/rss/rss_session.h b/src/base/rss/rss_session.h index 79c920066..9fee14c1e 100644 --- a/src/base/rss/rss_session.h +++ b/src/base/rss/rss_session.h @@ -149,7 +149,7 @@ namespace RSS private: QUuid generateUID() const; void load(); - void loadFolder(const QJsonObject &jsonObj, Folder *folder); + bool loadFolder(const QJsonObject &jsonObj, Folder *folder); void loadLegacy(); void store(); nonstd::expected prepareItemDest(const QString &path);