Browse Source

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
reviewable/pr6507/r7
Anthony Bilinski 4 years ago
parent
commit
658ce18e2d
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 26
      src/persistence/globalsettingsupgrader.cpp
  2. 7
      src/persistence/paths.cpp
  3. 1
      src/persistence/paths.h
  4. 2
      src/persistence/settings.cpp

26
src/persistence/globalsettingsupgrader.cpp

@ -18,8 +18,30 @@ @@ -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 @@ -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 @@ -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;

7
src/persistence/paths.cpp

@ -379,4 +379,11 @@ QString Paths::getUserNodesFilePath() const @@ -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

1
src/persistence/paths.h

@ -53,6 +53,7 @@ public: @@ -53,6 +53,7 @@ public:
QString getAppCacheDirPath() const;
QString getExampleNodesFilePath() const;
QString getUserNodesFilePath() const;
QString getBackupUserNodesFilePath() const;
#endif
private:

2
src/persistence/settings.cpp

@ -64,7 +64,7 @@ const QString Settings::globalSettingsFile = "qtox.ini"; @@ -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…
Cancel
Save