Merge branch 'charlesmchen/backupFixes'

pull/1/head
Matthew Chen 7 years ago
commit d821bd8e00

@ -4,8 +4,10 @@
<dict>
<key>BuildDetails</key>
<dict>
<key>CarthageVersion</key>
<string>0.31.1</string>
<key>OSXVersion</key>
<string>10.13.6</string>
<string>10.14</string>
<key>WebRTCCommit</key>
<string>ca71024b4993ba95e3e6b8d0758004cffc54ddaf M70</string>
</dict>

@ -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];
}

@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSBackupImportJob : OWSBackupJob
- (void)startAsync;
- (void)start;
@end

@ -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];
}
[self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_CONFIGURATION",
@"Indicates that the backup import is being configured.")
progress:nil];
- (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;
}
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];
}
@ -174,23 +164,27 @@ 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];
});
}
- (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<OWSBackupFragment *> *)items

@ -175,7 +175,7 @@ void AssertIsOnSendingQueue()
- (nullable NSError *)checkForPreconditionError
{
NSError *_Nullable error = [super checkForPreconditionError];
__block NSError *_Nullable error = [super checkForPreconditionError];
if (error) {
return error;
}
@ -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]]) {
error = OWSErrorMakeFailedToSendOutgoingMessageError();
break;
}
TSAttachmentStream *attachmentStream = (TSAttachmentStream *)attachment;
OWSAssertDebug(attachmentStream);
OWSAssertDebug(attachmentStream.serverId);
@ -193,7 +197,7 @@ void AssertIsOnSendingQueue()
}];
}
return nil;
return error;
}
- (void)run

Loading…
Cancel
Save