mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Respond to CR.
This commit is contained in:
parent
5c3bc74d06
commit
34d79265a1
|
@ -239,10 +239,7 @@ import CloudKit
|
|||
success: @escaping (()) -> Void,
|
||||
failure: @escaping (Error) -> Void) {
|
||||
|
||||
var recordIDs = [CKRecordID]()
|
||||
for recordName in recordNames {
|
||||
recordIDs.append(CKRecordID(recordName: recordName))
|
||||
}
|
||||
let recordIDs = recordNames.map { CKRecordID(recordName: $0) }
|
||||
let deleteOperation = CKModifyRecordsOperation(recordsToSave: nil, recordIDsToDelete: recordIDs)
|
||||
deleteOperation.modifyRecordsCompletionBlock = { (records, recordIds, error) in
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// Writes db entities using protobufs into snapshot fragments.
|
||||
// Snapshot fragments are compressed (they compress _very well_,
|
||||
// around 20x smaller) then encrypted. Ordering matters in
|
||||
// snapshot contents (entities should we restored in the same
|
||||
// snapshot contents (entities should be restored in the same
|
||||
// order they are serialized), so we are always careful to preserve
|
||||
// ordering of entities within a snapshot AND ordering of snapshot
|
||||
// fragments within a bakckup.
|
||||
|
@ -80,7 +80,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@property (nonatomic) NSMutableArray<OWSBackupExportItem *> *exportItems;
|
||||
|
||||
@property (nonatomic, nullable) OWSSignalServiceProtosBackupSnapshotBuilder *backupSnapshotBuilder;
|
||||
@property (nonatomic, nullable) OWSSignaliOSProtosBackupSnapshotBuilder *backupSnapshotBuilder;
|
||||
|
||||
@property (nonatomic) NSUInteger cachedItemCount;
|
||||
|
||||
|
@ -113,7 +113,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// use this state), but I think it'll be helpful to have around to future-proof
|
||||
// this work, help with debugging issue, etc.
|
||||
- (BOOL)writeObject:(TSYapDatabaseObject *)object
|
||||
entityType:(OWSSignalServiceProtosBackupSnapshotBackupEntityType)entityType
|
||||
entityType:(OWSSignaliOSProtosBackupSnapshotBackupEntityType)entityType
|
||||
{
|
||||
OWSAssert(object);
|
||||
|
||||
|
@ -124,11 +124,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
|
||||
if (!self.backupSnapshotBuilder) {
|
||||
self.backupSnapshotBuilder = [OWSSignalServiceProtosBackupSnapshotBuilder new];
|
||||
self.backupSnapshotBuilder = [OWSSignaliOSProtosBackupSnapshotBuilder new];
|
||||
}
|
||||
|
||||
OWSSignalServiceProtosBackupSnapshotBackupEntityBuilder *entityBuilder =
|
||||
[OWSSignalServiceProtosBackupSnapshotBackupEntityBuilder new];
|
||||
OWSSignaliOSProtosBackupSnapshotBackupEntityBuilder *entityBuilder =
|
||||
[OWSSignaliOSProtosBackupSnapshotBackupEntityBuilder new];
|
||||
[entityBuilder setType:entityType];
|
||||
[entityBuilder setEntityData:data];
|
||||
|
||||
|
@ -426,12 +426,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
NSString *,
|
||||
Class,
|
||||
EntityFilter _Nullable,
|
||||
OWSSignalServiceProtosBackupSnapshotBackupEntityType);
|
||||
OWSSignaliOSProtosBackupSnapshotBackupEntityType);
|
||||
ExportBlock exportEntities = ^(YapDatabaseReadTransaction *transaction,
|
||||
NSString *collection,
|
||||
Class expectedClass,
|
||||
EntityFilter _Nullable filter,
|
||||
OWSSignalServiceProtosBackupSnapshotBackupEntityType entityType) {
|
||||
OWSSignaliOSProtosBackupSnapshotBackupEntityType entityType) {
|
||||
__block NSUInteger count = 0;
|
||||
[transaction
|
||||
enumerateKeysAndObjectsInCollection:collection
|
||||
|
@ -469,7 +469,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[TSThread collection],
|
||||
[TSThread class],
|
||||
nil,
|
||||
OWSSignalServiceProtosBackupSnapshotBackupEntityTypeThread);
|
||||
OWSSignaliOSProtosBackupSnapshotBackupEntityTypeThread);
|
||||
if (aborted) {
|
||||
return;
|
||||
}
|
||||
|
@ -499,7 +499,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
return YES;
|
||||
},
|
||||
OWSSignalServiceProtosBackupSnapshotBackupEntityTypeAttachment);
|
||||
OWSSignaliOSProtosBackupSnapshotBackupEntityTypeAttachment);
|
||||
if (aborted) {
|
||||
return;
|
||||
}
|
||||
|
@ -523,7 +523,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
return YES;
|
||||
},
|
||||
OWSSignalServiceProtosBackupSnapshotBackupEntityTypeInteraction);
|
||||
OWSSignaliOSProtosBackupSnapshotBackupEntityTypeInteraction);
|
||||
if (aborted) {
|
||||
return;
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[OWSDatabaseMigration collection],
|
||||
[OWSDatabaseMigration class],
|
||||
nil,
|
||||
OWSSignalServiceProtosBackupSnapshotBackupEntityTypeMigration);
|
||||
OWSSignaliOSProtosBackupSnapshotBackupEntityTypeMigration);
|
||||
}];
|
||||
|
||||
if (aborted || self.isComplete) {
|
||||
|
@ -568,28 +568,36 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
self.savedDatabaseItems = [NSMutableArray new];
|
||||
self.savedAttachmentItems = [NSMutableArray new];
|
||||
|
||||
unsigned long long totalFileSize = 0;
|
||||
NSUInteger totalFileCount = 0;
|
||||
{
|
||||
unsigned long long totalFileSize = 0;
|
||||
unsigned long long databaseFileSize = 0;
|
||||
for (OWSBackupExportItem *item in self.unsavedDatabaseItems) {
|
||||
totalFileSize += [OWSFileSystem fileSizeOfPath:item.encryptedItem.filePath].unsignedLongLongValue;
|
||||
databaseFileSize += [OWSFileSystem fileSizeOfPath:item.encryptedItem.filePath].unsignedLongLongValue;
|
||||
}
|
||||
DDLogInfo(@"%@ exporting %@: count: %zd, bytes: %llu.",
|
||||
self.logTag,
|
||||
@"database items",
|
||||
self.unsavedDatabaseItems.count,
|
||||
totalFileSize);
|
||||
databaseFileSize);
|
||||
totalFileSize += databaseFileSize;
|
||||
totalFileCount += self.unsavedDatabaseItems.count;
|
||||
}
|
||||
{
|
||||
unsigned long long totalFileSize = 0;
|
||||
unsigned long long attachmentFileSize = 0;
|
||||
for (OWSAttachmentExport *attachmentExport in self.unsavedAttachmentExports) {
|
||||
totalFileSize += [OWSFileSystem fileSizeOfPath:attachmentExport.attachmentFilePath].unsignedLongLongValue;
|
||||
attachmentFileSize +=
|
||||
[OWSFileSystem fileSizeOfPath:attachmentExport.attachmentFilePath].unsignedLongLongValue;
|
||||
}
|
||||
DDLogInfo(@"%@ exporting %@: count: %zd, bytes: %llu.",
|
||||
self.logTag,
|
||||
@"attachment items",
|
||||
self.unsavedAttachmentExports.count,
|
||||
totalFileSize);
|
||||
attachmentFileSize);
|
||||
totalFileSize += attachmentFileSize;
|
||||
totalFileCount += self.unsavedAttachmentExports.count;
|
||||
}
|
||||
DDLogInfo(@"%@ exporting %@: count: %zd, bytes: %llu.", self.logTag, @"all items", totalFileCount, totalFileSize);
|
||||
|
||||
[self saveNextFileToCloudWithCompletion:completion];
|
||||
}
|
||||
|
|
|
@ -13,6 +13,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// TODO:
|
||||
static const NSUInteger kOWSBackupKeyLength = 32;
|
||||
|
||||
// LZMA algorithm significantly outperforms the other compressionlib options
|
||||
// for our database snapshots and is a widely adopted standard.
|
||||
static const compression_algorithm SignalCompressionAlgorithm = COMPRESSION_LZMA;
|
||||
|
||||
@implementation OWSBackupEncryptedItem
|
||||
|
||||
@end
|
||||
|
@ -196,9 +200,8 @@ static const NSUInteger kOWSBackupKeyLength = 32;
|
|||
if (!dstBuffer) {
|
||||
return nil;
|
||||
}
|
||||
// TODO: Should we use COMPRESSION_LZFSE?
|
||||
size_t dstLength
|
||||
= compression_encode_buffer(dstBuffer, dstBufferLength, srcBuffer, srcLength, NULL, COMPRESSION_LZFSE);
|
||||
size_t dstLength = compression_encode_buffer(
|
||||
dstBuffer, dstBufferLength, srcBuffer, srcLength, NULL, SignalCompressionAlgorithm);
|
||||
NSData *compressedData = [NSData dataWithBytesNoCopy:dstBuffer length:dstLength freeWhenDone:YES];
|
||||
|
||||
DDLogVerbose(@"%@ compressed %zd -> %zd = %0.2f",
|
||||
|
@ -233,9 +236,8 @@ static const NSUInteger kOWSBackupKeyLength = 32;
|
|||
if (!dstBuffer) {
|
||||
return nil;
|
||||
}
|
||||
// TODO: Should we use COMPRESSION_LZFSE?
|
||||
size_t dstLength
|
||||
= compression_decode_buffer(dstBuffer, dstBufferLength, srcBuffer, srcLength, NULL, COMPRESSION_LZFSE);
|
||||
size_t dstLength = compression_decode_buffer(
|
||||
dstBuffer, dstBufferLength, srcBuffer, srcLength, NULL, SignalCompressionAlgorithm);
|
||||
NSData *decompressedData = [NSData dataWithBytesNoCopy:dstBuffer length:dstLength freeWhenDone:YES];
|
||||
OWSAssert(decompressedData.length == uncompressedDataLength);
|
||||
DDLogVerbose(@"%@ decompressed %zd -> %zd = %0.2f",
|
||||
|
|
|
@ -515,15 +515,15 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
|
|||
aborted = YES;
|
||||
return completion(NO);
|
||||
}
|
||||
OWSSignalServiceProtosBackupSnapshot *_Nullable entities =
|
||||
[OWSSignalServiceProtosBackupSnapshot parseFromData:uncompressedData];
|
||||
OWSSignaliOSProtosBackupSnapshot *_Nullable entities =
|
||||
[OWSSignaliOSProtosBackupSnapshot parseFromData:uncompressedData];
|
||||
if (!entities || entities.entity.count < 1) {
|
||||
DDLogError(@"%@ missing entities.", self.logTag);
|
||||
// Database-related errors are unrecoverable.
|
||||
aborted = YES;
|
||||
return completion(NO);
|
||||
}
|
||||
for (OWSSignalServiceProtosBackupSnapshotBackupEntity *entity in entities.entity) {
|
||||
for (OWSSignaliOSProtosBackupSnapshotBackupEntity *entity in entities.entity) {
|
||||
NSData *_Nullable entityData = entity.entityData;
|
||||
if (entityData.length < 1) {
|
||||
DDLogError(@"%@ missing entity data.", self.logTag);
|
||||
|
|
Loading…
Reference in a new issue