From 6b0cb8dadba9db95517633c1b2f7220d049e470a Mon Sep 17 00:00:00 2001 From: benevanoff Date: Mon, 5 Apr 2021 18:56:19 -0500 Subject: support pruning of new databases --- src/daemon/DaemonManager.cpp | 16 +++++++++++++++- src/daemon/DaemonManager.h | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/daemon/DaemonManager.cpp b/src/daemon/DaemonManager.cpp index b7fb12db..5eadb792 100644 --- a/src/daemon/DaemonManager.cpp +++ b/src/daemon/DaemonManager.cpp @@ -27,6 +27,7 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "DaemonManager.h" +#include "common/util.h" #include #include #include @@ -47,7 +48,7 @@ namespace { static const int DAEMON_START_TIMEOUT_SECONDS = 120; } -bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const QString &dataDir, const QString &bootstrapNodeAddress, bool noSync /* = false*/) +bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const QString &dataDir, const QString &bootstrapNodeAddress, bool noSync /* = false*/, bool pruneBlockchain /* = false*/) { if (!QFileInfo(m_monerod).isFile()) { @@ -85,6 +86,12 @@ bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const arguments << "--bootstrap-daemon-address" << bootstrapNodeAddress; } + if (pruneBlockchain) { + if (!checkLmdbExists(dataDir)) { // check that DB has not already been created + arguments << "--prune-blockchain"; + } + } + if (noSync) { arguments << "--no-sync"; } @@ -322,6 +329,13 @@ QVariantMap DaemonManager::validateDataDir(const QString &dataDir) const return result; } +bool DaemonManager::checkLmdbExists(QString datadir) { + if (datadir.isEmpty() || datadir.isNull()) { + datadir = QString::fromStdString(tools::get_default_data_dir()); + } + return validateDataDir(datadir).value("lmdbExists").value(); +} + DaemonManager::DaemonManager(QObject *parent) : QObject(parent) , m_scheduler(this) diff --git a/src/daemon/DaemonManager.h b/src/daemon/DaemonManager.h index ac94c50d..2f884665 100644 --- a/src/daemon/DaemonManager.h +++ b/src/daemon/DaemonManager.h @@ -47,7 +47,7 @@ public: explicit DaemonManager(QObject *parent = 0); ~DaemonManager(); - Q_INVOKABLE bool start(const QString &flags, NetworkType::Type nettype, const QString &dataDir = "", const QString &bootstrapNodeAddress = "", bool noSync = false); + Q_INVOKABLE bool start(const QString &flags, NetworkType::Type nettype, const QString &dataDir = "", const QString &bootstrapNodeAddress = "", bool noSync = false, bool pruneBlockchain = false); Q_INVOKABLE void stopAsync(NetworkType::Type nettype, const QJSValue& callback); Q_INVOKABLE bool noSync() const noexcept; @@ -57,6 +57,7 @@ public: Q_INVOKABLE void sendCommandAsync(const QStringList &cmd, NetworkType::Type nettype, const QJSValue& callback) const; Q_INVOKABLE void exit(); Q_INVOKABLE QVariantMap validateDataDir(const QString &dataDir) const; + Q_INVOKABLE bool checkLmdbExists(QString datadir); private: -- cgit v1.2.3