diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h @@ -229,10 +229,7 @@ jsi::String backupDataKey, jsi::String backupLogDataKey, jsi::String maxVersion) override; - virtual jsi::Value retrieveBackupKeys( - jsi::Runtime &rt, - jsi::String backupSecret, - jsi::String backupID) override; + virtual jsi::Value retrieveBackupKeys(jsi::Runtime &rt) override; virtual jsi::Value retrieveLatestBackupInfo( jsi::Runtime &rt, jsi::String userIdentifier) override; diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.h --- a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.h +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.h @@ -15,5 +15,6 @@ static void restoreFromBackupLog( const std::vector &backupLog, size_t futureID); + static void setBackupID(std::string backupID, size_t futureID); }; } // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.cpp b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.cpp --- a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.cpp +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.cpp @@ -61,4 +61,19 @@ }; GlobalDBSingleton::instance.scheduleOrRunCancellable(job); } + +void BackupOperationsExecutor::setBackupID( + std::string backupID, + size_t futureID) { + taskType job = [backupID, futureID]() { + try { + DatabaseManager::getQueryExecutor().setMetadata("backupID", backupID); + ::resolveUnitFuture(futureID); + } catch (const std::exception &e) { + ::rejectFuture(futureID, rust::String(e.what())); + Logger::log("Setting backupID failed. Details: " + std::string(e.what())); + } + }; + GlobalDBSingleton::instance.scheduleOrRunCancellable(job); +} } // namespace comm diff --git a/native/native_rust_library/RustBackupExecutor.h b/native/native_rust_library/RustBackupExecutor.h --- a/native/native_rust_library/RustBackupExecutor.h +++ b/native/native_rust_library/RustBackupExecutor.h @@ -17,5 +17,6 @@ rust::Str maxVersion, size_t futureID); void restoreFromBackupLog(rust::Vec backupLog, size_t futureID); +void setBackupID(rust::Str backupID, size_t futureID); } // namespace comm diff --git a/native/native_rust_library/RustBackupExecutor.cpp b/native/native_rust_library/RustBackupExecutor.cpp --- a/native/native_rust_library/RustBackupExecutor.cpp +++ b/native/native_rust_library/RustBackupExecutor.cpp @@ -36,6 +36,10 @@ std::string(backupID), futureID); } +void setBackupID(rust::Str backupID, size_t futureID) { + BackupOperationsExecutor::setBackupID(std::string(backupID), futureID); +} + void restoreFromMainCompaction( rust::Str mainCompactionPath, rust::Str mainCompactionEncryptionKey, diff --git a/native/native_rust_library/src/backup.rs b/native/native_rust_library/src/backup.rs --- a/native/native_rust_library/src/backup.rs +++ b/native/native_rust_library/src/backup.rs @@ -8,7 +8,7 @@ create_main_compaction, get_backup_directory_path, get_backup_user_keys_file_path, get_siwe_backup_message_path, restore_from_backup_log, restore_from_main_compaction, secure_store_get, - string_callback, void_callback, + set_backup_id, string_callback, void_callback, }; use crate::utils::future_manager; use crate::utils::jsi_callbacks::handle_string_result_as_callback; @@ -126,6 +126,13 @@ return; } + let (future_id, future) = future_manager::new_future::<()>().await; + set_backup_id(&backup_id, future_id); + if let Err(err) = future.await { + handle_backup_creation_error(backup_id.clone(), err.to_string()); + return; + } + trigger_backup_file_upload(); // The promise will be resolved when the backup is uploaded }); diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs --- a/native/native_rust_library/src/lib.rs +++ b/native/native_rust_library/src/lib.rs @@ -527,6 +527,9 @@ #[cxx_name = "restoreFromBackupLog"] fn restore_from_backup_log(backup_log: Vec, future_id: usize); + + #[cxx_name = "setBackupID"] + fn set_backup_id(backup_id: &str, future_id: usize); } // Future handling from C++