diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIBackup.m b/Signal/src/ViewControllers/DebugUI/DebugUIBackup.m index bad3604d4..ee9d39b33 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIBackup.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIBackup.m @@ -99,12 +99,6 @@ NS_ASSUME_NONNULL_BEGIN actionWithTitle:@"Restore" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) { - [[OWSPrimaryStorage.sharedManager newDatabaseConnection] - readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - [transaction removeAllObjectsInCollection:[TSThread collection]]; - [transaction removeAllObjectsInCollection:[TSInteraction collection]]; - [transaction removeAllObjectsInCollection:[TSAttachment collection]]; - }]; [OWSBackup.sharedManager tryToImportBackup]; }]]; [controller addAction:[OWSAlerts cancelAction]]; diff --git a/Signal/src/util/OWSBackupImportJob.m b/Signal/src/util/OWSBackupImportJob.m index 7bf192ac3..d187d318e 100644 --- a/Signal/src/util/OWSBackupImportJob.m +++ b/Signal/src/util/OWSBackupImportJob.m @@ -415,17 +415,21 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe continue; } if ([dstTransaction numberOfKeysInCollection:collection] > 0) { - DDLogError(@"%@ cannot restore into non-empty database (%@).", self.logTag, collection); - aborted = YES; - return completion(NO); + DDLogError(@"%@ unexpected contents in database (%@).", self.logTag, collection); } } - // Clear existing migrations. + // Clear existing database contents. // - // This is safe since we only ever import into an empty database. - // Non-database migrations should be idempotent. - [dstTransaction removeAllObjectsInCollection:[OWSDatabaseMigration collection]]; + // This should be safe since we only ever import into an empty database. + // + // Note that if the app receives a message after registering and before restoring + // backup, it will be lost. + // + // Note that this will clear all migrations. + for (NSString *collection in collectionsToRestore) { + [dstTransaction removeAllObjectsInCollection:collection]; + } // Copy database entities. for (NSString *collection in collectionsToRestore) {