mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(core): One time reset of user bootstrap node list to default
Due to poor design, bootstrapNodes.json was saved the same if manually set by user, or if just storing qTox defaults. Because of this, for users using defaults, they would be stuck with stale defaults indefinitely without this one time reset. The user list that's removed is backed up to bootstrapNodes.backup.json. Going forward, the user list and default list will be stored separately. Fix #6452
This commit is contained in:
parent
08fdd3a2c7
commit
4580d3f106
@ -18,8 +18,30 @@
|
||||
*/
|
||||
|
||||
#include "globalsettingsupgrader.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/persistence/paths.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
||||
namespace {
|
||||
bool version0to1(Settings& settings)
|
||||
{
|
||||
const auto& paths = settings.getPaths();
|
||||
|
||||
QFile badFile{paths.getUserNodesFilePath()};
|
||||
if (badFile.exists()) {
|
||||
if (!badFile.rename(paths.getBackupUserNodesFilePath())) {
|
||||
qCritical() << "Failed to write to" << paths.getBackupUserNodesFilePath() << \
|
||||
"aborting bootstrap node upgrade.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
qWarning() << "Moved" << badFile.fileName() << "to" << paths.getBackupUserNodesFilePath() << \
|
||||
"to mitigate a bug. Resetting bootstrap nodes to default.";
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@ -37,7 +59,7 @@ bool GlobalSettingsUpgrader::doUpgrade(Settings& settings, int fromVer, int toVe
|
||||
}
|
||||
|
||||
using SettingsUpgradeFn = bool (*)(Settings&);
|
||||
std::vector<SettingsUpgradeFn> upgradeFns = {};
|
||||
std::vector<SettingsUpgradeFn> upgradeFns = {version0to1};
|
||||
|
||||
assert(fromVer < static_cast<int>(upgradeFns.size()));
|
||||
assert(toVer == static_cast<int>(upgradeFns.size()));
|
||||
@ -45,7 +67,7 @@ bool GlobalSettingsUpgrader::doUpgrade(Settings& settings, int fromVer, int toVe
|
||||
for (int i = fromVer; i < static_cast<int>(upgradeFns.size()); ++i) {
|
||||
auto const newSettingsVersion = i + 1;
|
||||
if (!upgradeFns[i](settings)) {
|
||||
qCritical() << "Failed to upgrade settings to version " << newSettingsVersion << " aborting";
|
||||
qCritical() << "Failed to upgrade settings to version" << newSettingsVersion << "aborting";
|
||||
return false;
|
||||
}
|
||||
qDebug() << "Settings upgraded incrementally to schema version " << newSettingsVersion;
|
||||
|
@ -379,4 +379,11 @@ QString Paths::getUserNodesFilePath() const
|
||||
return dir.filePath(nodesFileName);
|
||||
}
|
||||
|
||||
QString Paths::getBackupUserNodesFilePath() const
|
||||
{
|
||||
QDir dir(getSettingsDirPath());
|
||||
constexpr static char nodesFileName[] = "bootstrapNodes.backup.json";
|
||||
return dir.filePath(nodesFileName);
|
||||
}
|
||||
|
||||
#endif // PATHS_VERSION_TCS_COMPLIANT
|
||||
|
@ -53,6 +53,7 @@ public:
|
||||
QString getAppCacheDirPath() const;
|
||||
QString getExampleNodesFilePath() const;
|
||||
QString getUserNodesFilePath() const;
|
||||
QString getBackupUserNodesFilePath() const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
@ -64,7 +64,7 @@ const QString Settings::globalSettingsFile = "qtox.ini";
|
||||
Settings* Settings::settings{nullptr};
|
||||
CompatibleRecursiveMutex Settings::bigLock;
|
||||
QThread* Settings::settingsThread{nullptr};
|
||||
static constexpr int GLOBAL_SETTINGS_VERSION = 0;
|
||||
static constexpr int GLOBAL_SETTINGS_VERSION = 1;
|
||||
static constexpr int PERSONAL_SETTINGS_VERSION = 0;
|
||||
|
||||
Settings::Settings()
|
||||
|
Loading…
x
Reference in New Issue
Block a user