Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33064320
D14800.1768436763.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D14800.1768436763.diff
View Options
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
@@ -310,11 +310,14 @@
std::string newLogEncryptionKey) {
std::string finalBackupPath =
PlatformSpecificTools::getBackupFilePath(backupID, false, false);
+ std::string finalBackupVersionInfoPath =
+ PlatformSpecificTools::getBackupFilePath(backupID, false, true);
std::string finalAttachmentsPath =
PlatformSpecificTools::getBackupFilePath(backupID, true, false);
std::string tempBackupPath = finalBackupPath + "_tmp";
std::string tempAttachmentsPath = finalAttachmentsPath + "_tmp";
+ std::string tempVersionPath = finalBackupVersionInfoPath + "_tmp";
if (SQLiteUtils::fileExists(tempBackupPath)) {
Logger::log(
@@ -329,14 +332,24 @@
if (SQLiteUtils::fileExists(tempAttachmentsPath)) {
Logger::log(
"Attempting to delete temporary attachments file from previous "
- "backup "
- "attempt.");
+ "backup attempt.");
SQLiteUtils::attemptDeleteFile(
tempAttachmentsPath,
"Failed to delete temporary attachments file from previous backup "
"attempt.");
}
+ if (SQLiteUtils::fileExists(tempVersionPath)) {
+ Logger::log(
+ "Attempting to delete temporary version file from previous backup "
+ "attempt.");
+ SQLiteUtils::attemptDeleteFile(
+ tempVersionPath,
+ "Failed to delete temporary version file from previous backup "
+ "attempt.");
+ }
+
+ // handle main compaction
sqlite3 *backupDB;
sqlite3_open(tempBackupPath.c_str(), &backupDB);
SQLiteUtils::setEncryptionKey(backupDB, mainCompactionEncryptionKey);
@@ -381,6 +394,7 @@
"Failed to rename complete temporary backup file to final backup "
"file.");
+ // handle attachments
std::ofstream tempAttachmentsFile(tempAttachmentsPath);
if (!tempAttachmentsFile.is_open()) {
std::string errorMessage{
@@ -409,6 +423,26 @@
"Failed to rename complete temporary attachments file to final "
"attachments file.");
+ // handle db version info
+ std::ofstream tempVersionFile(tempVersionPath);
+ if (!tempVersionFile.is_open()) {
+ std::string errorMessage{
+ "Unable to create version file for backup id: " + backupID};
+ Logger::log(errorMessage);
+ throw std::runtime_error(errorMessage);
+ }
+ int dbVersion = SQLiteUtils::getDatabaseVersion(
+ DatabaseManager::mainConnectionManager->getConnection());
+ tempVersionFile << dbVersion;
+ tempVersionFile.close();
+
+ SQLiteUtils::attemptRenameFile(
+ tempVersionPath,
+ finalBackupVersionInfoPath,
+ "Failed to rename complete temporary version file to final version "
+ "file.");
+
+ // update logs to use new backup
DatabaseManager::getQueryExecutor().setMetadata("backupID", backupID);
DatabaseManager::getQueryExecutor().clearMetadata("logID");
if (ServicesUtils::fullBackupSupport) {
diff --git a/native/native_rust_library/src/backup/upload_handler.rs b/native/native_rust_library/src/backup/upload_handler.rs
--- a/native/native_rust_library/src/backup/upload_handler.rs
+++ b/native/native_rust_library/src/backup/upload_handler.rs
@@ -336,11 +336,17 @@
Err(err) => return Err(err.into()),
};
+ let db_version_path = get_backup_file_path(&backup_id, false, true)?;
+ let db_version = match tokio::fs::read_to_string(&db_version_path).await {
+ Ok(data) => data.parse::<u16>().ok(),
+ Err(err) if err.kind() == ErrorKind::NotFound => None,
+ Err(err) => return Err(err.into()),
+ };
+
let version_info = backup_client::BackupVersionInfo {
code_version: crate::generated::CODE_VERSION as u16,
state_version: crate::generated::STATE_VERSION as u16,
- // TODO: Pass DB version value here
- ..Default::default()
+ db_version: db_version.unwrap_or_default(),
};
let backup_data = BackupData {
@@ -374,6 +380,7 @@
let backup_files_cleanup = async {
let paths_to_remove = vec![
get_backup_file_path(&backup_id, false, false)?,
+ get_backup_file_path(&backup_id, false, true)?,
get_backup_user_keys_file_path(&backup_id)?,
get_backup_file_path(&backup_id, true, false)?,
get_siwe_backup_message_path(&backup_id)?,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 15, 12:26 AM (8 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5933585
Default Alt Text
D14800.1768436763.diff (4 KB)
Attached To
Mode
D14800: [native] Upload DB version with backup info
Attached
Detach File
Event Timeline
Log In to Comment