From 1c820fc2f6e5c638abd16164a7852f923bc9d83e Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 23 Jan 2022 19:47:50 +0100 Subject: [PATCH] lmdb: Fix storage initialization when config file cannot be loaded --- librepomgr/serversetup.cpp | 23 ++++++++++++++--------- librepomgr/serversetup.h | 3 ++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/librepomgr/serversetup.cpp b/librepomgr/serversetup.cpp index 11358b6..2a9b3c7 100644 --- a/librepomgr/serversetup.cpp +++ b/librepomgr/serversetup.cpp @@ -218,7 +218,7 @@ std::vector> ServiceSetup::BuildSetup::getBuildActi return buildActions; } -void ServiceSetup::loadConfigFiles(bool restoreStateAndDiscardDatabases) +void ServiceSetup::loadConfigFiles(bool doFirstTimeSetup) { // read config file cout << Phrases::InfoMessage << "Reading config file: " << configFilePath << Phrases::EndFlush; @@ -264,11 +264,9 @@ void ServiceSetup::loadConfigFiles(bool restoreStateAndDiscardDatabases) } } // restore state/cache and discard databases - if (restoreStateAndDiscardDatabases) { - restoreState(); - config.initStorage(dbPath.data(), maxDbs); - config.markAllDatabasesToBeDiscarded(); - restoreStateAndDiscardDatabases = false; + if (doFirstTimeSetup) { + initStorage(); + doFirstTimeSetup = false; } // read webserver, build and user configuration (partially cached so read it after the cache has been restored to override cached values) for (const auto &iniEntry : configIni.data()) { @@ -288,9 +286,8 @@ void ServiceSetup::loadConfigFiles(bool restoreStateAndDiscardDatabases) } // restore state/cache and discard databases if not done yet - if (restoreStateAndDiscardDatabases) { - restoreState(); - config.markAllDatabasesToBeDiscarded(); + if (doFirstTimeSetup) { + initStorage(); } // read pacman config @@ -622,6 +619,14 @@ std::size_t ServiceSetup::saveState() return size; } +void ServiceSetup::initStorage() +{ + cout << Phrases::InfoMessage << "Opening LMDB file: " << dbPath << " (max DBs: " << maxDbs << ')' << Phrases::EndFlush; + config.initStorage(dbPath.data(), maxDbs); + restoreState(); + config.markAllDatabasesToBeDiscarded(); +} + void ServiceSetup::run() { #ifndef CPP_UTILITIES_DEBUG_BUILD diff --git a/librepomgr/serversetup.h b/librepomgr/serversetup.h index 6512dc9..4d4a7a3 100644 --- a/librepomgr/serversetup.h +++ b/librepomgr/serversetup.h @@ -144,13 +144,14 @@ struct LIBREPOMGR_EXPORT ServiceSetup : public LibPkg::Lockable { LockTable m_locksByName; } locks; - void loadConfigFiles(bool restoreStateAndDiscardDatabases); + void loadConfigFiles(bool doFirstTimeSetup); void printDatabases(); std::string_view cacheFilePath() const; RAPIDJSON_NAMESPACE::Document libraryDependenciesToJson(); void restoreLibraryDependenciesFromJson(const std::string &json, ReflectiveRapidJSON::JsonDeserializationErrors *errors); std::size_t restoreState(); std::size_t saveState(); + void initStorage(); void run(); ServiceStatus computeStatus() const; };