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 @@ -7,6 +7,8 @@ #include "SQLiteQueryExecutor.h" #include "SQLiteUtils.h" +#include + namespace comm { const int DatabaseManager::backupDataKeySize = 64; @@ -41,7 +43,19 @@ std::string backupDataKey = DatabaseManager::generateBackupDataKey(); std::string backupLogDataKey = DatabaseManager::generateBackupLogDataKey(); - SQLiteQueryExecutor::clearSensitiveData(backupDataKey, backupLogDataKey); + + SQLiteQueryExecutor::connectionManager.closeConnection(); + if (SQLiteUtils::fileExists(SQLiteQueryExecutor::sqliteFilePath) && + std::remove(SQLiteQueryExecutor::sqliteFilePath.c_str())) { + std::ostringstream errorStream; + errorStream << "Failed to delete database file. Details: " + << strerror(errno); + Logger::log(errorStream.str()); + throw std::system_error(errno, std::generic_category(), errorStream.str()); + } + SQLiteQueryExecutor::backupDataKey = backupDataKey; + SQLiteQueryExecutor::backupLogDataKey = backupLogDataKey; + SQLiteQueryExecutor::migrate(); PlatformSpecificTools::removeBackupDirectory(); CommMMKV::clearSensitiveData(); diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h @@ -23,7 +23,6 @@ namespace comm { class SQLiteQueryExecutor : public DatabaseQueryExecutor { - static void migrate(); static void closeConnection(); #ifndef EMSCRIPTEN @@ -56,6 +55,7 @@ SQLiteQueryExecutor(std::string sqliteFilePath); static sqlite3 *getConnection(); + static void migrate(); std::unique_ptr getThread(std::string threadID) const override; std::string getDraft(std::string key) const override; @@ -212,8 +212,6 @@ getDMOperationsByType(const std::string &operationType) const override; #ifndef EMSCRIPTEN - static void - clearSensitiveData(std::string &backupDataKey, std::string &backupLogDataKey); static void initialize( std::string &databasePath, std::string &backupDataKey, diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp @@ -1652,22 +1652,6 @@ } #ifndef EMSCRIPTEN -void SQLiteQueryExecutor::clearSensitiveData( - std::string &backupDataKey, - std::string &backupLogDataKey) { - SQLiteQueryExecutor::connectionManager.closeConnection(); - if (SQLiteUtils::fileExists(SQLiteQueryExecutor::sqliteFilePath) && - std::remove(SQLiteQueryExecutor::sqliteFilePath.c_str())) { - std::ostringstream errorStream; - errorStream << "Failed to delete database file. Details: " - << strerror(errno); - Logger::log(errorStream.str()); - throw std::system_error(errno, std::generic_category(), errorStream.str()); - } - SQLiteQueryExecutor::backupDataKey = backupDataKey; - SQLiteQueryExecutor::backupLogDataKey = backupLogDataKey; - SQLiteQueryExecutor::migrate(); -} void SQLiteQueryExecutor::initialize( std::string &databasePath,