Merge branch 'charlesmchen/backupFixes'

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

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

@ -520,7 +520,7 @@ NSError *OWSBackupErrorWithDescription(NSString *description)
_backupImportState = OWSBackupState_InProgress; _backupImportState = OWSBackupState_InProgress;
self.backupImportJob = [[OWSBackupImportJob alloc] initWithDelegate:self recipientId:recipientId]; self.backupImportJob = [[OWSBackupImportJob alloc] initWithDelegate:self recipientId:recipientId];
[self.backupImportJob startAsync]; [self.backupImportJob start];
[self postDidChangeNotification]; [self postDidChangeNotification];
} }

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

@ -79,7 +79,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
return self.manifest.attachmentsItems; return self.manifest.attachmentsItems;
} }
- (void)startAsync - (void)start
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
@ -91,36 +91,24 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
[[self.backup ensureCloudKitAccess] [[self.backup ensureCloudKitAccess]
.thenInBackground(^{ .thenInBackground(^{
[self start]; [self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_CONFIGURATION",
}) @"Indicates that the backup import is being configured.")
.catch(^(NSError *error) { progress:nil];
[self failWithErrorDescription:
NSLocalizedString(@"BACKUP_IMPORT_ERROR_COULD_NOT_IMPORT",
@"Error indicating the backup import could not import the user's data.")];
}) retainUntilComplete];
}
- (void)start return [self configureImport];
{ })
[self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_CONFIGURATION", .thenInBackground(^{
@"Indicates that the backup import is being configured.") if (self.isComplete) {
progress:nil]; return
[AnyPromise promiseWithValue:OWSBackupErrorWithDescription(@"Backup import no longer active.")];
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;
}
[self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_IMPORT", [self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_IMPORT",
@"Indicates that the backup import data is being imported.") @"Indicates that the backup import data is being imported.")
progress:nil]; progress:nil];
[[self downloadAndProcessManifestWithBackupIO:self.backupIO] return [self downloadAndProcessManifestWithBackupIO:self.backupIO];
})
.thenInBackground(^(OWSBackupManifestContents *manifest) { .thenInBackground(^(OWSBackupManifestContents *manifest) {
OWSCAssertDebug(manifest.databaseItems.count > 0); OWSCAssertDebug(manifest.databaseItems.count > 0);
OWSCAssertDebug(manifest.attachmentsItems); OWSCAssertDebug(manifest.attachmentsItems);
@ -129,8 +117,10 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
return [self downloadAndProcessImport]; return [self downloadAndProcessImport];
}) })
.catchInBackground(^(NSError *error) { .catch(^(NSError *error) {
[self failWithError:error]; [self failWithErrorDescription:
NSLocalizedString(@"BACKUP_IMPORT_ERROR_COULD_NOT_IMPORT",
@"Error indicating the backup import could not import the user's data.")];
}) retainUntilComplete]; }) retainUntilComplete];
} }
@ -174,23 +164,27 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
[self.profileManager fetchLocalUsersProfile]; [self.profileManager fetchLocalUsersProfile];
[self.tsAccountManager updateAccountAttributes]; [self.tsAccountManager updateAccountAttributes];
// Make sure backup is enabled once we complete
// a backup restore.
[OWSBackup.sharedManager setIsBackupEnabled:YES];
[self succeed]; [self succeed];
}); });
} }
- (BOOL)configureImport - (AnyPromise *)configureImport
{ {
OWSLogVerbose(@""); OWSLogVerbose(@"");
if (![self ensureJobTempDir]) { if (![self ensureJobTempDir]) {
OWSFailDebug(@"Could not create jobTempDirPath."); OWSFailDebug(@"Could not create jobTempDirPath.");
return NO; return [AnyPromise promiseWithValue:OWSBackupErrorWithDescription(@"Could not create jobTempDirPath.")];
} }
self.backupIO = [[OWSBackupIO alloc] initWithJobTempDirPath:self.jobTempDirPath]; self.backupIO = [[OWSBackupIO alloc] initWithJobTempDirPath:self.jobTempDirPath];
return YES; return [AnyPromise promiseWithValue:@(1)];
} }
- (AnyPromise *)downloadFilesFromCloud:(NSMutableArray<OWSBackupFragment *> *)items - (AnyPromise *)downloadFilesFromCloud:(NSMutableArray<OWSBackupFragment *> *)items

@ -175,7 +175,7 @@ void AssertIsOnSendingQueue()
- (nullable NSError *)checkForPreconditionError - (nullable NSError *)checkForPreconditionError
{ {
NSError *_Nullable error = [super checkForPreconditionError]; __block NSError *_Nullable error = [super checkForPreconditionError];
if (error) { if (error) {
return error; return error;
} }
@ -184,7 +184,11 @@ void AssertIsOnSendingQueue()
if (self.message.hasAttachments) { if (self.message.hasAttachments) {
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
for (TSAttachment *attachment in [self.message attachmentsWithTransaction: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; TSAttachmentStream *attachmentStream = (TSAttachmentStream *)attachment;
OWSAssertDebug(attachmentStream); OWSAssertDebug(attachmentStream);
OWSAssertDebug(attachmentStream.serverId); OWSAssertDebug(attachmentStream.serverId);
@ -193,7 +197,7 @@ void AssertIsOnSendingQueue()
}]; }];
} }
return nil; return error;
} }
- (void)run - (void)run

Loading…
Cancel
Save