Skip to content

Commit

Permalink
Implement C++ file to expose backup API
Browse files Browse the repository at this point in the history
Summary:
This differential implements C++ class that allows to safely trigger backup creation and restoration from any place in C++ using GlobalDBSingleton. The real
application ofthis class will be exposing C++ backup API to Rust in the very next diff.

Test Plan: The same as for the parent differential but instead of directly calling `SQLiteQueryExecutor` call methods of this class.

Reviewers: kamil, michal

Reviewed By: michal

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D10509
  • Loading branch information
marcinwasowicz committed Jan 17, 2024
1 parent c07f1ab commit bec0c0b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions native/android/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ target_include_directories(
../../cpp/CommonCpp/NativeModules
../../cpp/CommonCpp/NativeModules/InternalModules
../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities
../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/BackupOperationsUtilities
../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores
../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/ThreadOperationsUtilities
../../cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities
Expand Down
10 changes: 10 additions & 0 deletions native/cpp/CommonCpp/NativeModules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ set(DATA_STORES_SRCS
${_data_stores_path}/UserStore.cpp
)

set(_backup_op_path ./PersistentStorageUtilities/BackupOperationsUtilities)
set(BACKUP_OP_HDRS
${_backup_op_path}/BackupOperationsExecutor.h
)
set(BACKUP_OP_SRCS
${_backup_op_path}/BackupOperationsExecutor.cpp
)

add_library(comm-modules-persistentstorage
${MESSAGE_HDRS}
${MESSAGE_SRCS}
Expand All @@ -96,6 +104,8 @@ add_library(comm-modules-persistentstorage
${THREAD_OP_SRCS}
${DATA_STORES_HDRS}
${DATA_STORES_SRCS}
${BACKUP_OP_HDRS}
${BACKUP_OP_SRCS}
)

# reference local directory when building, use installation path when installing
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "BackupOperationsExecutor.h"
#include "DatabaseManager.h"
#include "GlobalDBSingleton.h"
#include "Logger.h"
#include "WorkerThread.h"

namespace comm {
void BackupOperationsExecutor::createMainCompaction(std::string backupID) {
taskType job = [backupID]() {
try {
DatabaseManager::getQueryExecutor().createMainCompaction(backupID);
} catch (const std::exception &e) {
// TODO: Inform Rust networking about main
// compaction creation failure
Logger::log(
"Main compaction creation failed. Details: " + std::string(e.what()));
}
};
GlobalDBSingleton::instance.scheduleOrRunCancellable(job);
}

void BackupOperationsExecutor::restoreFromMainCompaction(
std::string mainCompactionPath,
std::string mainCompactionEncryptionKey) {
taskType job = [mainCompactionPath, mainCompactionEncryptionKey]() {
try {
DatabaseManager::getQueryExecutor().restoreFromMainCompaction(
mainCompactionPath, mainCompactionEncryptionKey);
} catch (const std::exception &e) {
// TODO: Inform Rust networking about failure
// of restoration from main compaction.
Logger::log(
"Restore from main compaction failed. Details: " +
std::string(e.what()));
}
};
GlobalDBSingleton::instance.scheduleOrRunCancellable(job);
}
} // namespace comm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <string>

namespace comm {
class BackupOperationsExecutor {
public:
static void createMainCompaction(std::string backupID);
static void restoreFromMainCompaction(
std::string mainCompactionPath,
std::string mainCompactionEncryptionKey);
};
} // namespace comm
14 changes: 14 additions & 0 deletions native/ios/Comm.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
CB7EF17E295C674300B17035 /* CommIOSNotifications.mm in Sources */ = {isa = PBXBuildFile; fileRef = CB7EF17D295C5D1800B17035 /* CommIOSNotifications.mm */; };
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 */; };
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 */; };
Expand Down Expand Up @@ -273,6 +274,8 @@
CB7EF17D295C5D1800B17035 /* CommIOSNotifications.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = CommIOSNotifications.mm; path = Comm/CommIOSNotifications/CommIOSNotifications.mm; sourceTree = "<group>"; };
CB90951929531663002F2A7F /* CommIOSNotifications.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommIOSNotifications.h; path = Comm/CommIOSNotifications/CommIOSNotifications.h; sourceTree = "<group>"; };
CBA784382B28AC4300E9F419 /* CommServicesAuthMetadataEmitter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommServicesAuthMetadataEmitter.h; sourceTree = "<group>"; };
CBAAA46E2B459181007599DA /* BackupOperationsExecutor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BackupOperationsExecutor.cpp; path = PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.cpp; sourceTree = "<group>"; };
CBAAA46F2B459181007599DA /* BackupOperationsExecutor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BackupOperationsExecutor.h; path = PersistentStorageUtilities/BackupOperationsUtilities/BackupOperationsExecutor.h; sourceTree = "<group>"; };
CBCA09042A8E0E6B00F75B3E /* StaffUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StaffUtils.h; sourceTree = "<group>"; };
CBCA09052A8E0E6B00F75B3E /* StaffUtils.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StaffUtils.cpp; sourceTree = "<group>"; };
CBCF57AB2B05096F00EC4BC0 /* AESCryptoModuleObjCCompat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AESCryptoModuleObjCCompat.h; path = Comm/CommAESCryptoUtils/AESCryptoModuleObjCCompat.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -716,6 +719,15 @@
name = CommIOSNotifications;
sourceTree = "<group>";
};
CBAAA46D2B45915F007599DA /* BackupOperationsUtilities */ = {
isa = PBXGroup;
children = (
CBAAA46E2B459181007599DA /* BackupOperationsExecutor.cpp */,
CBAAA46F2B459181007599DA /* BackupOperationsExecutor.h */,
);
name = BackupOperationsUtilities;
sourceTree = "<group>";
};
CBCF57A92B05091D00EC4BC0 /* CommAESCryptoUtils */ = {
isa = PBXGroup;
children = (
Expand All @@ -727,6 +739,7 @@
CBED0E2C284E086100CD3863 /* PersistentStorageUtilities */ = {
isa = PBXGroup;
children = (
CBAAA46D2B45915F007599DA /* BackupOperationsUtilities */,
8EA59BD02A6E786200EB4F53 /* DataStores */,
CBFE582628858512003B94C9 /* ThreadOperationsUtilities */,
CB38F2AC286C6C010010535C /* MessageOperationsUtilities */,
Expand Down Expand Up @@ -1083,6 +1096,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CBAAA4702B459181007599DA /* BackupOperationsExecutor.cpp in Sources */,
CBCA09062A8E0E7400F75B3E /* StaffUtils.cpp in Sources */,
8EF7756B2A7433630046A385 /* ThreadStore.cpp in Sources */,
CB2689002A2DF58000EC7300 /* CommConstants.cpp in Sources */,
Expand Down

0 comments on commit bec0c0b

Please sign in to comment.