diff --git a/native/android/app/CMakeLists.txt b/native/android/app/CMakeLists.txt --- a/native/android/app/CMakeLists.txt +++ b/native/android/app/CMakeLists.txt @@ -130,6 +130,7 @@ "../../native_rust_library/RustAESCrypto.cpp" "../../native_rust_library/RustCSAMetadataEmitter.cpp" "../../native_rust_library/RustSecureStore.cpp" + "../../native_rust_library/RustBackupExecutor.cpp" ) file(GLOB CRYPTO_NATIVE_CODE "../../cpp/CommonCpp/CryptoTools/*.cpp") file(GLOB DB_NATIVE_CODE "../../cpp/CommonCpp/DatabaseManagers/*.cpp") diff --git a/native/ios/Comm.xcodeproj/project.pbxproj b/native/ios/Comm.xcodeproj/project.pbxproj --- a/native/ios/Comm.xcodeproj/project.pbxproj +++ b/native/ios/Comm.xcodeproj/project.pbxproj @@ -79,6 +79,7 @@ CB7EF180295C674300B17035 /* CommIOSNotificationsBridgeQueue.mm in Sources */ = {isa = PBXBuildFile; fileRef = CB7EF17B295C580500B17035 /* CommIOSNotificationsBridgeQueue.mm */; }; CB90951F29534B32002F2A7F /* CommSecureStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 71D4D7CB26C50B1000FCDBCD /* CommSecureStore.mm */; }; CBAAA4702B459181007599DA /* BackupOperationsExecutor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CBAAA46E2B459181007599DA /* BackupOperationsExecutor.cpp */; }; + CBAAA4732B45A9B0007599DA /* RustBackupExecutor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CBAAA4712B45A9B0007599DA /* RustBackupExecutor.cpp */; }; CBCA09062A8E0E7400F75B3E /* StaffUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CBCA09052A8E0E6B00F75B3E /* StaffUtils.cpp */; }; CBCA09072A8E0E7D00F75B3E /* StaffUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CBCA09052A8E0E6B00F75B3E /* StaffUtils.cpp */; }; CBDEC69B28ED867000C17588 /* GlobalDBSingleton.mm in Sources */ = {isa = PBXBuildFile; fileRef = CBDEC69A28ED867000C17588 /* GlobalDBSingleton.mm */; }; @@ -275,6 +276,8 @@ CBA784382B28AC4300E9F419 /* CommServicesAuthMetadataEmitter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommServicesAuthMetadataEmitter.h; sourceTree = ""; }; CBAAA46E2B459181007599DA /* BackupOperationsExecutor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BackupOperationsExecutor.cpp; path = PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.cpp; sourceTree = ""; }; CBAAA46F2B459181007599DA /* BackupOperationsExecutor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BackupOperationsExecutor.h; path = PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.h; sourceTree = ""; }; + CBAAA4712B45A9B0007599DA /* RustBackupExecutor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RustBackupExecutor.cpp; sourceTree = ""; }; + CBAAA4722B45A9B0007599DA /* RustBackupExecutor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RustBackupExecutor.h; sourceTree = ""; }; CBCA09042A8E0E6B00F75B3E /* StaffUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StaffUtils.h; sourceTree = ""; }; CBCA09052A8E0E6B00F75B3E /* StaffUtils.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StaffUtils.cpp; sourceTree = ""; }; CBCF57AB2B05096F00EC4BC0 /* AESCryptoModuleObjCCompat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AESCryptoModuleObjCCompat.h; path = Comm/CommAESCryptoUtils/AESCryptoModuleObjCCompat.h; sourceTree = ""; }; @@ -596,6 +599,8 @@ 8B99AF6B28D50D4800EB5ADB /* native_rust_library */ = { isa = PBXGroup; children = ( + CBAAA4712B45A9B0007599DA /* RustBackupExecutor.cpp */, + CBAAA4722B45A9B0007599DA /* RustBackupExecutor.h */, CB74AB1E2B2B0C0900CBB494 /* RustCSAMetadataEmitter.cpp */, CB74AB1F2B2B0C0900CBB494 /* RustCSAMetadataEmitter.h */, DFD5E7842B052B1400C32B6A /* RustAESCrypto.cpp */, @@ -1133,6 +1138,7 @@ 71D4D7CC26C50B1000FCDBCD /* CommSecureStore.mm in Sources */, 8B38121629CE5742000C52E9 /* RustPromiseManager.cpp in Sources */, 7FBB2A7629E94539002C6493 /* utilsJSI-generated.cpp in Sources */, + CBAAA4732B45A9B0007599DA /* RustBackupExecutor.cpp in Sources */, 711B408425DA97F9005F8F06 /* dummy.swift in Sources */, 8E86A6D329537EBB000BBE7D /* DatabaseManager.cpp in Sources */, CBDEC69B28ED867000C17588 /* GlobalDBSingleton.mm in Sources */, diff --git a/native/native_rust_library/RustBackupExecutor.h b/native/native_rust_library/RustBackupExecutor.h new file mode 100644 --- /dev/null +++ b/native/native_rust_library/RustBackupExecutor.h @@ -0,0 +1,14 @@ +#pragma once + +#include "cxx.h" + +namespace comm { + +rust::String getBackupDirectoryPath(); +rust::String getBackupFilePath(rust::String backupID, bool isAttachments); +void createMainCompaction(rust::String backupID); +void restoreFromMainCompaction( + rust::String mainCompactionPath, + rust::String mainCompactionEncryptionKey); + +} // namespace comm diff --git a/native/native_rust_library/RustBackupExecutor.cpp b/native/native_rust_library/RustBackupExecutor.cpp new file mode 100644 --- /dev/null +++ b/native/native_rust_library/RustBackupExecutor.cpp @@ -0,0 +1,29 @@ +#include "RustBackupExecutor.h" +#include "../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.h" +#include "../cpp/CommonCpp/Tools/PlatformSpecificTools.h" + +#include + +namespace comm { + +rust::String getBackupDirectoryPath() { + return rust::String(PlatformSpecificTools::getBackupDirectoryPath()); +} + +rust::String getBackupFilePath(rust::String backupID, bool isAttachments) { + return rust::String(PlatformSpecificTools::getBackupFilePath( + std::string(backupID), isAttachments)); +} + +void createMainCompaction(rust::String backupID) { + BackupOperationsExecutor::createMainCompaction(std::string(backupID)); +} + +void restoreFromMainCompaction( + rust::String mainCompactionPath, + rust::String mainCompactionEncryptionKey) { + BackupOperationsExecutor::restoreFromMainCompaction( + std::string(mainCompactionPath), + std::string(mainCompactionEncryptionKey)); +} +} // namespace comm 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 @@ -244,6 +244,34 @@ #[cxx_name = "secureStoreGet"] fn secure_store_get(key: &str) -> Result; } + + // C++ Backup creation + #[namespace = "comm"] + unsafe extern "C++" { + include!("RustBackupExecutor.h"); + + #[allow(unused)] + #[cxx_name = "getBackupDirectoryPath"] + fn get_backup_directory_path() -> Result; + + #[allow(unused)] + #[cxx_name = "getBackupFilePath"] + fn get_backup_file_path( + backup_id: String, + is_attachments: bool, + ) -> Result; + + #[allow(unused)] + #[cxx_name = "createMainCompaction"] + fn create_main_compaction(backup_id: String) -> Result<()>; + + #[allow(unused)] + #[cxx_name = "restoreFromMainCompaction"] + fn restore_from_main_compaction( + main_compaction_path: String, + main_compaction_encryption_key: String, + ) -> Result<()>; + } } fn handle_string_result_as_callback(