From 15dc7b2c7c4fd6c4bfaca1eae907618fa630c688 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 26 Nov 2018 17:11:09 -0500 Subject: [PATCH 1/6] Enable backup after successful backup restore. --- Signal/src/util/Backup/OWSBackupImportJob.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Signal/src/util/Backup/OWSBackupImportJob.m b/Signal/src/util/Backup/OWSBackupImportJob.m index 7c0c76adf..f82a9dfa6 100644 --- a/Signal/src/util/Backup/OWSBackupImportJob.m +++ b/Signal/src/util/Backup/OWSBackupImportJob.m @@ -569,6 +569,15 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe return promise; } +- (void)succeed +{ + // Make sure backup is enabled once we complete + // a backup restore. + [OWSBackup.sharedManager setIsBackupEnabled:YES]; + + [super succeed]; +} + @end NS_ASSUME_NONNULL_END From ca65325710932ad67df29ddb5e5e5176665aec5b Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 26 Nov 2018 17:11:20 -0500 Subject: [PATCH 2/6] Don't send messages with restoring attachments. --- SignalServiceKit/src/Messages/OWSMessageSender.m | 6 +++++- SignalServiceKit/src/Util/OWSError.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 3cf3d7629..7a3cecd0e 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -184,7 +184,11 @@ void AssertIsOnSendingQueue() if (self.message.hasAttachments) { [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { for (TSAttachment *attachment in [self.message attachmentsWithTransaction:transaction]) { - OWSAssertDebug([attachment isKindOfClass:[TSAttachmentStream class]]); + if (![attachment isKindOfClass:[TSAttachmentStream class]]) { + return OWSErrorWithCodeDescription( + OWSErrorCodeMessageHasInvalidAttachments, @"Message with missing attachments cannot be sent."); + } + TSAttachmentStream *attachmentStream = (TSAttachmentStream *)attachment; OWSAssertDebug(attachmentStream); OWSAssertDebug(attachmentStream.serverId); diff --git a/SignalServiceKit/src/Util/OWSError.h b/SignalServiceKit/src/Util/OWSError.h index 238ab6b6d..cd8f20fa7 100644 --- a/SignalServiceKit/src/Util/OWSError.h +++ b/SignalServiceKit/src/Util/OWSError.h @@ -51,6 +51,7 @@ typedef NS_ENUM(NSInteger, OWSErrorCode) { OWSErrorCodeProfileUpdateFailed = 777424, OWSErrorCodeAvatarWriteFailed = 777425, OWSErrorCodeAvatarUploadFailed = 777426, + OWSErrorCodeMessageHasInvalidAttachments, }; extern NSString *const OWSErrorRecipientIdentifierKey; From 08de701d6eb98276534af3617b6afe735837388d Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 27 Nov 2018 09:54:18 -0500 Subject: [PATCH 3/6] Clean up ahead of CR. --- SignalServiceKit/src/Messages/OWSMessageSender.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 7a3cecd0e..b0f24f135 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -175,7 +175,7 @@ void AssertIsOnSendingQueue() - (nullable NSError *)checkForPreconditionError { - NSError *_Nullable error = [super checkForPreconditionError]; + __block NSError *_Nullable error = [super checkForPreconditionError]; if (error) { return error; } @@ -185,8 +185,9 @@ void AssertIsOnSendingQueue() [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { for (TSAttachment *attachment in [self.message attachmentsWithTransaction:transaction]) { if (![attachment isKindOfClass:[TSAttachmentStream class]]) { - return OWSErrorWithCodeDescription( + error = OWSErrorWithCodeDescription( OWSErrorCodeMessageHasInvalidAttachments, @"Message with missing attachments cannot be sent."); + break; } TSAttachmentStream *attachmentStream = (TSAttachmentStream *)attachment; @@ -197,7 +198,7 @@ void AssertIsOnSendingQueue() }]; } - return nil; + return error; } - (void)run From 4b7b7c19bedd07e529af156c5f90a16eba5b72c4 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 29 Nov 2018 09:25:56 -0500 Subject: [PATCH 4/6] Clean up. --- Signal/src/util/Backup/OWSBackupImportJob.m | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Signal/src/util/Backup/OWSBackupImportJob.m b/Signal/src/util/Backup/OWSBackupImportJob.m index f82a9dfa6..1bd67c878 100644 --- a/Signal/src/util/Backup/OWSBackupImportJob.m +++ b/Signal/src/util/Backup/OWSBackupImportJob.m @@ -174,7 +174,11 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe [self.profileManager fetchLocalUsersProfile]; [self.tsAccountManager updateAccountAttributes]; - + + // Make sure backup is enabled once we complete + // a backup restore. + [OWSBackup.sharedManager setIsBackupEnabled:YES]; + [self succeed]; }); } @@ -569,15 +573,6 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe return promise; } -- (void)succeed -{ - // Make sure backup is enabled once we complete - // a backup restore. - [OWSBackup.sharedManager setIsBackupEnabled:YES]; - - [super succeed]; -} - @end NS_ASSUME_NONNULL_END From 0a6d54e8b127fbfee62746d73e575161856b4454 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 29 Nov 2018 10:32:27 -0500 Subject: [PATCH 5/6] Clean up ahead of CR. --- Signal/Signal-Info.plist | 4 +- Signal/src/util/Backup/OWSBackup.m | 2 +- Signal/src/util/Backup/OWSBackupImportJob.h | 2 +- Signal/src/util/Backup/OWSBackupImportJob.m | 56 +++++++++------------ 4 files changed, 28 insertions(+), 36 deletions(-) diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index de4ba5fb7..ac61dc3a2 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -4,8 +4,10 @@ BuildDetails + CarthageVersion + 0.31.1 OSXVersion - 10.13.6 + 10.14 WebRTCCommit ca71024b4993ba95e3e6b8d0758004cffc54ddaf M70 diff --git a/Signal/src/util/Backup/OWSBackup.m b/Signal/src/util/Backup/OWSBackup.m index 00cd59432..49b9190db 100644 --- a/Signal/src/util/Backup/OWSBackup.m +++ b/Signal/src/util/Backup/OWSBackup.m @@ -520,7 +520,7 @@ NSError *OWSBackupErrorWithDescription(NSString *description) _backupImportState = OWSBackupState_InProgress; self.backupImportJob = [[OWSBackupImportJob alloc] initWithDelegate:self recipientId:recipientId]; - [self.backupImportJob startAsync]; + [self.backupImportJob start]; [self postDidChangeNotification]; } diff --git a/Signal/src/util/Backup/OWSBackupImportJob.h b/Signal/src/util/Backup/OWSBackupImportJob.h index 6e92b6a5d..969e2c668 100644 --- a/Signal/src/util/Backup/OWSBackupImportJob.h +++ b/Signal/src/util/Backup/OWSBackupImportJob.h @@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN @interface OWSBackupImportJob : OWSBackupJob -- (void)startAsync; +- (void)start; @end diff --git a/Signal/src/util/Backup/OWSBackupImportJob.m b/Signal/src/util/Backup/OWSBackupImportJob.m index 1bd67c878..1f902e285 100644 --- a/Signal/src/util/Backup/OWSBackupImportJob.m +++ b/Signal/src/util/Backup/OWSBackupImportJob.m @@ -79,7 +79,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe return self.manifest.attachmentsItems; } -- (void)startAsync +- (void)start { OWSAssertIsOnMainThread(); @@ -91,36 +91,24 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe [[self.backup ensureCloudKitAccess] .thenInBackground(^{ - [self start]; - }) - .catch(^(NSError *error) { - [self failWithErrorDescription: - NSLocalizedString(@"BACKUP_IMPORT_ERROR_COULD_NOT_IMPORT", - @"Error indicating the backup import could not import the user's data.")]; - }) retainUntilComplete]; -} - -- (void)start -{ - [self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_CONFIGURATION", - @"Indicates that the backup import is being configured.") - progress:nil]; - - if (![self configureImport]) { - [self failWithErrorDescription:NSLocalizedString(@"BACKUP_IMPORT_ERROR_COULD_NOT_IMPORT", - @"Error indicating the backup import could not import the user's data.")]; - return; - } + [self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_CONFIGURATION", + @"Indicates that the backup import is being configured.") + progress:nil]; - if (self.isComplete) { - return; - } + return [self configureImport]; + }) + .thenInBackground(^{ + if (self.isComplete) { + return + [AnyPromise promiseWithValue:OWSBackupErrorWithDescription(@"Backup import no longer active.")]; + } - [self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_IMPORT", - @"Indicates that the backup import data is being imported.") - progress:nil]; + [self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_IMPORT", + @"Indicates that the backup import data is being imported.") + progress:nil]; - [[self downloadAndProcessManifestWithBackupIO:self.backupIO] + return [self downloadAndProcessManifestWithBackupIO:self.backupIO]; + }) .thenInBackground(^(OWSBackupManifestContents *manifest) { OWSCAssertDebug(manifest.databaseItems.count > 0); OWSCAssertDebug(manifest.attachmentsItems); @@ -129,8 +117,10 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe return [self downloadAndProcessImport]; }) - .catchInBackground(^(NSError *error) { - [self failWithError:error]; + .catch(^(NSError *error) { + [self failWithErrorDescription: + NSLocalizedString(@"BACKUP_IMPORT_ERROR_COULD_NOT_IMPORT", + @"Error indicating the backup import could not import the user's data.")]; }) retainUntilComplete]; } @@ -183,18 +173,18 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe }); } -- (BOOL)configureImport +- (AnyPromise *)configureImport { OWSLogVerbose(@""); if (![self ensureJobTempDir]) { OWSFailDebug(@"Could not create jobTempDirPath."); - return NO; + return [AnyPromise promiseWithValue:OWSBackupErrorWithDescription(@"Could not create jobTempDirPath.")]; } self.backupIO = [[OWSBackupIO alloc] initWithJobTempDirPath:self.jobTempDirPath]; - return YES; + return [AnyPromise promiseWithValue:@(1)]; } - (AnyPromise *)downloadFilesFromCloud:(NSMutableArray *)items From 7624b01d1b1b6dfc431c63316183694fcd36eae3 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 29 Nov 2018 14:48:56 -0500 Subject: [PATCH 6/6] Respond to CR. --- SignalServiceKit/src/Messages/OWSMessageSender.m | 3 +-- SignalServiceKit/src/Util/OWSError.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index b0f24f135..ba14dadca 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -185,8 +185,7 @@ void AssertIsOnSendingQueue() [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { for (TSAttachment *attachment in [self.message attachmentsWithTransaction:transaction]) { if (![attachment isKindOfClass:[TSAttachmentStream class]]) { - error = OWSErrorWithCodeDescription( - OWSErrorCodeMessageHasInvalidAttachments, @"Message with missing attachments cannot be sent."); + error = OWSErrorMakeFailedToSendOutgoingMessageError(); break; } diff --git a/SignalServiceKit/src/Util/OWSError.h b/SignalServiceKit/src/Util/OWSError.h index cd8f20fa7..238ab6b6d 100644 --- a/SignalServiceKit/src/Util/OWSError.h +++ b/SignalServiceKit/src/Util/OWSError.h @@ -51,7 +51,6 @@ typedef NS_ENUM(NSInteger, OWSErrorCode) { OWSErrorCodeProfileUpdateFailed = 777424, OWSErrorCodeAvatarWriteFailed = 777425, OWSErrorCodeAvatarUploadFailed = 777426, - OWSErrorCodeMessageHasInvalidAttachments, }; extern NSString *const OWSErrorRecipientIdentifierKey;