diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h @@ -4,7 +4,6 @@ #include "DatabaseQueryExecutor.h" #include "NativeSQLiteConnectionManager.h" #include "SQLiteQueryExecutor.h" -#include "WebSQLiteConnectionManager.h" #include @@ -15,10 +14,9 @@ // database. // DatabaseIdentifier::MAIN connectionManager. static std::shared_ptr mainConnectionManager; - // Backup database after decrypting (at backup level) is not encrypted, so we - // use an unencrypted connection manager. // DatabaseIdentifier::RESTORED connectionManager. - static std::shared_ptr restoredConnectionManager; + static std::shared_ptr + restoredConnectionManager; // Indicate that at least one instance of SQLiteQueryExecutor was created, // which is identical to finishing the migration process and having a fully diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp @@ -21,9 +21,7 @@ std::shared_ptr DatabaseManager::mainConnectionManager; -// Backup database after decrypting (at backup level) is not encrypted, so we -// use an unencrypted connection manager. -std::shared_ptr +std::shared_ptr DatabaseManager::restoredConnectionManager; std::once_flag DatabaseManager::queryExecutorCreationIndicated; @@ -421,13 +419,13 @@ std::string mainCompactionPath, std::string mainCompactionEncryptionKey, std::string maxVersion) { - std::string backupPath = SQLiteBackup::restoreFromMainCompaction( - mainCompactionPath, - mainCompactionEncryptionKey, - std::nullopt, - maxVersion); + SQLiteBackup::validateMainCompaction( + mainCompactionPath, mainCompactionEncryptionKey); + // At this point, logs are already applied to the database, and we don't have + // access to it, so we use just an empty string. DatabaseManager::restoredConnectionManager = - std::make_shared(backupPath); + std::make_shared( + mainCompactionPath, mainCompactionEncryptionKey, ""); } void DatabaseManager::copyContentFromBackupDatabase() { diff --git a/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.h b/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.h --- a/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.h +++ b/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.h @@ -23,9 +23,9 @@ public: NativeSQLiteConnectionManager( - std::string &databasePath, - std::string &backupDataKey, - std::string &backupLogDataKey); + std::string databasePath, + std::string backupDataKey, + std::string backupLogDataKey); ~NativeSQLiteConnectionManager(); sqlite3 *getEphemeralConnection() const override; diff --git a/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp b/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp @@ -181,9 +181,9 @@ } NativeSQLiteConnectionManager::NativeSQLiteConnectionManager( - std::string &databasePath, - std::string &backupDataKey, - std::string &backupLogDataKey) + std::string databasePath, + std::string backupDataKey, + std::string backupLogDataKey) : SQLiteConnectionManager(databasePath), backupLogsSession(nullptr), backupDataKey(backupDataKey),