Sketch out OWSBackupStorage.

pull/1/head
Matthew Chen 7 years ago
parent 792be8018f
commit 46a89e89f0

@ -1 +1 @@
Subproject commit aae15b5fb1fc718f19b862390b61f540e45a36ee Subproject commit 93e79025cf285042cb397f3f4d1e0d52c68b9ecc

@ -10,27 +10,16 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
// void runSyncRegistrationsForStorage(OWSStorage *storage);
// void runAsyncRegistrationsForStorage(OWSStorage *storage);
@interface OWSBackupStorage : OWSStorage @interface OWSBackupStorage : OWSStorage
- (instancetype)init NS_UNAVAILABLE; - (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; - (YapDatabaseConnection *)dbConnection;
//
//+ (nullable NSError *)migrateToSharedData;
//
//+ (NSString *)databaseFilePath;
//
//+ (NSString *)legacyDatabaseFilePath;
//+ (NSString *)legacyDatabaseFilePath_SHM;
//+ (NSString *)legacyDatabaseFilePath_WAL;
//+ (NSString *)sharedDataDatabaseFilePath;
//+ (NSString *)sharedDataDatabaseFilePath_SHM;
//+ (NSString *)sharedDataDatabaseFilePath_WAL;
@end @end

@ -3,28 +3,11 @@
// //
#import "OWSBackupStorage.h" #import "OWSBackupStorage.h"
#import "OWSFileSystem.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 "OWSStorage+Subclass.h" #import "OWSStorage+Subclass.h"
//#import "TSDatabaseSecondaryIndexes.h"
//#import "TSDatabaseView.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
NSString *const OWSBackupStorageExceptionName_CouldNotCreateDatabaseDirectory
= @"OWSBackupStorageExceptionName_CouldNotCreateDatabaseDirectory";
#pragma mark -
@interface OWSBackupStorage () @interface OWSBackupStorage ()
@property (nonatomic, readonly, nullable) YapDatabaseConnection *dbConnection; @property (nonatomic, readonly, nullable) YapDatabaseConnection *dbConnection;
@ -32,34 +15,32 @@ NSString *const OWSBackupStorageExceptionName_CouldNotCreateDatabaseDirectory
@property (atomic) BOOL areAsyncRegistrationsComplete; @property (atomic) BOOL areAsyncRegistrationsComplete;
@property (atomic) BOOL areSyncRegistrationsComplete; @property (atomic) BOOL areSyncRegistrationsComplete;
@property (nonatomic, readonly) NSString *databaseDirPath;
@property (nonatomic, readonly) NSData *databaseKeySpec;
@end @end
#pragma mark - #pragma mark -
@implementation OWSBackupStorage @implementation OWSBackupStorage
//+ (instancetype)sharedManager @synthesize databaseKeySpec = _databaseKeySpec;
//{
// static OWSBackupStorage *sharedManager = nil; - (instancetype)initBackupStorageWithdatabaseDirPath:(NSString *)databaseDirPath
// static dispatch_once_t onceToken; databaseKeySpec:(NSData *)databaseKeySpec
// dispatch_once(&onceToken, ^{
// sharedManager = [[self alloc] initStorage];
//
//#if TARGET_OS_IPHONE
// [OWSBackupStorage protectFiles];
//#endif
// });
// return sharedManager;
//}
- (instancetype)initStorage
{ {
OWSAssert(databaseDirPath.length > 0);
OWSAssert(databaseKeySpec.length > 0);
OWSAssert([OWSFileSystem ensureDirectoryExists:databaseDirPath]);
self = [super initStorage]; self = [super initStorage];
if (self) { if (self) {
_dbConnection = self.newDatabaseConnection; [self protectFiles];
OWSSingletonAssert(); _dbConnection = self.newDatabaseConnection;
_databaseDirPath = databaseDirPath;
_databaseKeySpec = databaseKeySpec;
} }
return self; return self;
@ -68,7 +49,6 @@ NSString *const OWSBackupStorageExceptionName_CouldNotCreateDatabaseDirectory
- (void)resetStorage - (void)resetStorage
{ {
_dbConnection = nil; _dbConnection = nil;
// _dbReadWriteConnection = nil;
[super resetStorage]; [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( DDLogInfo(@"%@ \t WAL file size: %@", self.logTag, [OWSFileSystem fileSizeOfPath:self.databaseFilePath_WAL]);
// @"%@ 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];
}
//+ (NSString *)legacyDatabaseDirPath // Protect the entire new database directory.
//{ [OWSFileSystem protectFileOrFolderAtPath:self.databaseDirPath];
// 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 + (NSString *)databaseFilename
{ {
return @"SignalBackup.sqlite"; return @"SignalBackup.sqlite";
} }
//+ (NSString *)databaseFilename_SHM - (NSString *)databaseFilename
//{ {
// return [self.databaseFilename stringByAppendingString:@"-shm"]; return OWSBackupStorage.databaseFilename;
//} }
//
//+ (NSString *)databaseFilename_WAL - (NSString *)databaseFilename_SHM
//{ {
// return [self.databaseFilename stringByAppendingString:@"-wal"]; return [self.databaseFilename stringByAppendingString:@"-shm"];
//} }
//
//+ (NSString *)legacyDatabaseFilePath - (NSString *)databaseFilename_WAL
//{ {
// return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename]; return [self.databaseFilename stringByAppendingString:@"-wal"];
//} }
//
//+ (NSString *)legacyDatabaseFilePath_SHM - (NSString *)databaseFilePath
//{ {
// return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM]; return [self.databaseDirPath stringByAppendingPathComponent:self.databaseFilename];
//} }
//
//+ (NSString *)legacyDatabaseFilePath_WAL - (NSString *)databaseFilePath_SHM
//{ {
// return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL]; return [self.databaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM];
//} }
//
//+ (NSString *)sharedDataDatabaseFilePath - (NSString *)databaseFilePath_WAL
//{ {
// return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename]; return [self.databaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL];
//} }
//
//+ (NSString *)sharedDataDatabaseFilePath_SHM - (NSData *)databaseKeySpec
//{ {
// return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM]; return self.databaseKeySpec;
//} }
//
//+ (NSString *)sharedDataDatabaseFilePath_WAL - (void)ensureDatabaseKeySpecExists
//{ {
// return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL]; // Do nothing.
//} }
//+ (NSString *)databaseFilePath
//{
// DDLogVerbose(@"%@ databasePath: %@", self.logTag, OWSBackupStorage.sharedDataDatabaseFilePath);
//
// return self.sharedDataDatabaseFilePath;
//}
//
//- (NSString *)databaseFilePath
//{
// return OWSBackupStorage.databaseFilePath;
//}
//+ (YapDatabaseConnection *)dbReadConnection
//{
// return OWSBackupStorage.sharedManager.dbReadConnection;
//}
//
//+ (YapDatabaseConnection *)dbReadWriteConnection
//{
// return OWSBackupStorage.sharedManager.dbReadWriteConnection;
//}
@end @end

Loading…
Cancel
Save