mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Sketch out OWSBackupStorage.
This commit is contained in:
parent
792be8018f
commit
46a89e89f0
3 changed files with 64 additions and 143 deletions
2
Pods
2
Pods
|
@ -1 +1 @@
|
|||
Subproject commit aae15b5fb1fc718f19b862390b61f540e45a36ee
|
||||
Subproject commit 93e79025cf285042cb397f3f4d1e0d52c68b9ecc
|
|
@ -10,27 +10,16 @@
|
|||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// void runSyncRegistrationsForStorage(OWSStorage *storage);
|
||||
// void runAsyncRegistrationsForStorage(OWSStorage *storage);
|
||||
|
||||
@interface OWSBackupStorage : OWSStorage
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
//+ (instancetype)sharedManager NS_SWIFT_NAME(shared());
|
||||
//
|
||||
- (instancetype)initStorage NS_UNAVAILABLE;
|
||||
|
||||
- (instancetype)initBackupStorageWithdatabaseDirPath:(NSString *)databaseDirPath
|
||||
databaseKeySpec:(NSData *)databaseKeySpec NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (YapDatabaseConnection *)dbConnection;
|
||||
//
|
||||
//+ (nullable NSError *)migrateToSharedData;
|
||||
//
|
||||
//+ (NSString *)databaseFilePath;
|
||||
//
|
||||
//+ (NSString *)legacyDatabaseFilePath;
|
||||
//+ (NSString *)legacyDatabaseFilePath_SHM;
|
||||
//+ (NSString *)legacyDatabaseFilePath_WAL;
|
||||
//+ (NSString *)sharedDataDatabaseFilePath;
|
||||
//+ (NSString *)sharedDataDatabaseFilePath_SHM;
|
||||
//+ (NSString *)sharedDataDatabaseFilePath_WAL;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -3,28 +3,11 @@
|
|||
//
|
||||
|
||||
#import "OWSBackupStorage.h"
|
||||
|
||||
//#import "AppContext.h"
|
||||
//#import "OWSAnalytics.h"
|
||||
//#import "OWSBatchMessageProcessor.h"
|
||||
//#import "OWSDisappearingMessagesFinder.h"
|
||||
//#import "OWSFailedAttachmentDownloadsJob.h"
|
||||
//#import "OWSFailedMessagesJob.h"
|
||||
//#import "OWSFileSystem.h"
|
||||
//#import "OWSIncomingMessageFinder.h"
|
||||
//#import "OWSMessageReceiver.h"
|
||||
#import "OWSFileSystem.h"
|
||||
#import "OWSStorage+Subclass.h"
|
||||
|
||||
//#import "TSDatabaseSecondaryIndexes.h"
|
||||
//#import "TSDatabaseView.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
NSString *const OWSBackupStorageExceptionName_CouldNotCreateDatabaseDirectory
|
||||
= @"OWSBackupStorageExceptionName_CouldNotCreateDatabaseDirectory";
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@interface OWSBackupStorage ()
|
||||
|
||||
@property (nonatomic, readonly, nullable) YapDatabaseConnection *dbConnection;
|
||||
|
@ -32,34 +15,32 @@ NSString *const OWSBackupStorageExceptionName_CouldNotCreateDatabaseDirectory
|
|||
@property (atomic) BOOL areAsyncRegistrationsComplete;
|
||||
@property (atomic) BOOL areSyncRegistrationsComplete;
|
||||
|
||||
@property (nonatomic, readonly) NSString *databaseDirPath;
|
||||
@property (nonatomic, readonly) NSData *databaseKeySpec;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSBackupStorage
|
||||
|
||||
//+ (instancetype)sharedManager
|
||||
//{
|
||||
// static OWSBackupStorage *sharedManager = nil;
|
||||
// static dispatch_once_t onceToken;
|
||||
// dispatch_once(&onceToken, ^{
|
||||
// sharedManager = [[self alloc] initStorage];
|
||||
//
|
||||
//#if TARGET_OS_IPHONE
|
||||
// [OWSBackupStorage protectFiles];
|
||||
//#endif
|
||||
// });
|
||||
// return sharedManager;
|
||||
//}
|
||||
@synthesize databaseKeySpec = _databaseKeySpec;
|
||||
|
||||
- (instancetype)initStorage
|
||||
- (instancetype)initBackupStorageWithdatabaseDirPath:(NSString *)databaseDirPath
|
||||
databaseKeySpec:(NSData *)databaseKeySpec
|
||||
{
|
||||
OWSAssert(databaseDirPath.length > 0);
|
||||
OWSAssert(databaseKeySpec.length > 0);
|
||||
OWSAssert([OWSFileSystem ensureDirectoryExists:databaseDirPath]);
|
||||
|
||||
self = [super initStorage];
|
||||
|
||||
if (self) {
|
||||
_dbConnection = self.newDatabaseConnection;
|
||||
[self protectFiles];
|
||||
|
||||
OWSSingletonAssert();
|
||||
_dbConnection = self.newDatabaseConnection;
|
||||
_databaseDirPath = databaseDirPath;
|
||||
_databaseKeySpec = databaseKeySpec;
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -68,7 +49,6 @@ NSString *const OWSBackupStorageExceptionName_CouldNotCreateDatabaseDirectory
|
|||
- (void)resetStorage
|
||||
{
|
||||
_dbConnection = nil;
|
||||
// _dbReadWriteConnection = nil;
|
||||
|
||||
[super resetStorage];
|
||||
}
|
||||
|
@ -113,108 +93,60 @@ NSString *const OWSBackupStorageExceptionName_CouldNotCreateDatabaseDirectory
|
|||
}];
|
||||
}
|
||||
|
||||
+ (void)protectFiles
|
||||
- (void)protectFiles
|
||||
{
|
||||
// TODO:
|
||||
DDLogInfo(@"%@ Database file size: %@", self.logTag, [OWSFileSystem fileSizeOfPath:self.databaseFilePath]);
|
||||
DDLogInfo(@"%@ \t SHM file size: %@", self.logTag, [OWSFileSystem fileSizeOfPath:self.databaseFilePath_SHM]);
|
||||
DDLogInfo(@"%@ \t WAL file size: %@", self.logTag, [OWSFileSystem fileSizeOfPath:self.databaseFilePath_WAL]);
|
||||
|
||||
// DDLogInfo(
|
||||
// @"%@ Database file size: %@", self.logTag, [OWSFileSystem
|
||||
// fileSizeOfPath:self.sharedDataDatabaseFilePath]);
|
||||
// DDLogInfo(
|
||||
// @"%@ \t SHM file size: %@", self.logTag, [OWSFileSystem
|
||||
// fileSizeOfPath:self.sharedDataDatabaseFilePath_SHM]);
|
||||
// DDLogInfo(
|
||||
// @"%@ \t WAL file size: %@", self.logTag, [OWSFileSystem
|
||||
// fileSizeOfPath:self.sharedDataDatabaseFilePath_WAL]);
|
||||
//
|
||||
// // Protect the entire new database directory.
|
||||
// [OWSFileSystem protectFileOrFolderAtPath:self.sharedDataDatabaseDirPath];
|
||||
// Protect the entire new database directory.
|
||||
[OWSFileSystem protectFileOrFolderAtPath:self.databaseDirPath];
|
||||
}
|
||||
|
||||
//+ (NSString *)legacyDatabaseDirPath
|
||||
//{
|
||||
// return [OWSFileSystem appDocumentDirectoryPath];
|
||||
//}
|
||||
//
|
||||
//+ (NSString *)sharedDataDatabaseDirPath
|
||||
//{
|
||||
// NSString *databaseDirPath = [[OWSFileSystem appSharedDataDirectoryPath]
|
||||
// stringByAppendingPathComponent:@"database"];
|
||||
//
|
||||
// if (![OWSFileSystem ensureDirectoryExists:databaseDirPath]) {
|
||||
// OWSRaiseException(
|
||||
// OWSBackupStorageExceptionName_CouldNotCreateDatabaseDirectory, @"Could not create new database
|
||||
// directory");
|
||||
// }
|
||||
// return databaseDirPath;
|
||||
//}
|
||||
|
||||
+ (NSString *)databaseFilename
|
||||
{
|
||||
return @"SignalBackup.sqlite";
|
||||
}
|
||||
|
||||
//+ (NSString *)databaseFilename_SHM
|
||||
//{
|
||||
// return [self.databaseFilename stringByAppendingString:@"-shm"];
|
||||
//}
|
||||
//
|
||||
//+ (NSString *)databaseFilename_WAL
|
||||
//{
|
||||
// return [self.databaseFilename stringByAppendingString:@"-wal"];
|
||||
//}
|
||||
//
|
||||
//+ (NSString *)legacyDatabaseFilePath
|
||||
//{
|
||||
// return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename];
|
||||
//}
|
||||
//
|
||||
//+ (NSString *)legacyDatabaseFilePath_SHM
|
||||
//{
|
||||
// return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM];
|
||||
//}
|
||||
//
|
||||
//+ (NSString *)legacyDatabaseFilePath_WAL
|
||||
//{
|
||||
// return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL];
|
||||
//}
|
||||
//
|
||||
//+ (NSString *)sharedDataDatabaseFilePath
|
||||
//{
|
||||
// return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename];
|
||||
//}
|
||||
//
|
||||
//+ (NSString *)sharedDataDatabaseFilePath_SHM
|
||||
//{
|
||||
// return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM];
|
||||
//}
|
||||
//
|
||||
//+ (NSString *)sharedDataDatabaseFilePath_WAL
|
||||
//{
|
||||
// return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL];
|
||||
//}
|
||||
- (NSString *)databaseFilename
|
||||
{
|
||||
return OWSBackupStorage.databaseFilename;
|
||||
}
|
||||
|
||||
//+ (NSString *)databaseFilePath
|
||||
//{
|
||||
// DDLogVerbose(@"%@ databasePath: %@", self.logTag, OWSBackupStorage.sharedDataDatabaseFilePath);
|
||||
//
|
||||
// return self.sharedDataDatabaseFilePath;
|
||||
//}
|
||||
//
|
||||
//- (NSString *)databaseFilePath
|
||||
//{
|
||||
// return OWSBackupStorage.databaseFilePath;
|
||||
//}
|
||||
- (NSString *)databaseFilename_SHM
|
||||
{
|
||||
return [self.databaseFilename stringByAppendingString:@"-shm"];
|
||||
}
|
||||
|
||||
//+ (YapDatabaseConnection *)dbReadConnection
|
||||
//{
|
||||
// return OWSBackupStorage.sharedManager.dbReadConnection;
|
||||
//}
|
||||
//
|
||||
//+ (YapDatabaseConnection *)dbReadWriteConnection
|
||||
//{
|
||||
// return OWSBackupStorage.sharedManager.dbReadWriteConnection;
|
||||
//}
|
||||
- (NSString *)databaseFilename_WAL
|
||||
{
|
||||
return [self.databaseFilename stringByAppendingString:@"-wal"];
|
||||
}
|
||||
|
||||
- (NSString *)databaseFilePath
|
||||
{
|
||||
return [self.databaseDirPath stringByAppendingPathComponent:self.databaseFilename];
|
||||
}
|
||||
|
||||
- (NSString *)databaseFilePath_SHM
|
||||
{
|
||||
return [self.databaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM];
|
||||
}
|
||||
|
||||
- (NSString *)databaseFilePath_WAL
|
||||
{
|
||||
return [self.databaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL];
|
||||
}
|
||||
|
||||
- (NSData *)databaseKeySpec
|
||||
{
|
||||
return self.databaseKeySpec;
|
||||
}
|
||||
|
||||
- (void)ensureDatabaseKeySpecExists
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
Loading…
Reference in a new issue