diff --git a/Signal/src/util/Backup/OWSBackupAPI.swift b/Signal/src/util/Backup/OWSBackupAPI.swift index eb6b70abf..6981bcc36 100644 --- a/Signal/src/util/Backup/OWSBackupAPI.swift +++ b/Signal/src/util/Backup/OWSBackupAPI.swift @@ -63,14 +63,17 @@ import PromiseKit // complete. @objc public class func saveEphemeralFileToCloudObjc(recipientId: String, + label: String, fileUrl: URL) -> AnyPromise { return AnyPromise(saveEphemeralFileToCloud(recipientId: recipientId, + label: label, fileUrl: fileUrl)) } public class func saveEphemeralFileToCloud(recipientId: String, + label: String, fileUrl: URL) -> Promise { - let recordName = "\(recordNamePrefix(forRecipientId: recipientId))ephemeralFile-\(NSUUID().uuidString)" + let recordName = "\(recordNamePrefix(forRecipientId: recipientId))ephemeral-\(label)-\(NSUUID().uuidString)" return saveFileToCloud(fileUrl: fileUrl, recordName: recordName, recordType: signalBackupRecordType) diff --git a/Signal/src/util/Backup/OWSBackupExportJob.m b/Signal/src/util/Backup/OWSBackupExportJob.m index ef4bd85bc..d1524035b 100644 --- a/Signal/src/util/Backup/OWSBackupExportJob.m +++ b/Signal/src/util/Backup/OWSBackupExportJob.m @@ -757,8 +757,9 @@ NS_ASSUME_NONNULL_BEGIN return [OWSBackupAPI saveEphemeralFileToCloudObjcWithRecipientId:self.recipientId - fileUrl:[NSURL fileURLWithPath:item.encryptedItem - .filePath]]; + label:@"database" + fileUrl:[NSURL + fileURLWithPath:item.encryptedItem.filePath]]; }) .thenInBackground(^(NSString *recordName) { item.recordName = recordName; @@ -908,6 +909,7 @@ NS_ASSUME_NONNULL_BEGIN exportItem.encryptedItem = encryptedItem; return [OWSBackupAPI saveEphemeralFileToCloudObjcWithRecipientId:self.recipientId + label:@"local-profile-avatar" fileUrl:[NSURL fileURLWithPath:encryptedItem.filePath]] .thenInBackground(^(NSString *recordName) { exportItem.recordName = recordName; diff --git a/Signal/src/util/Backup/OWSBackupImportJob.m b/Signal/src/util/Backup/OWSBackupImportJob.m index 42119e2ca..201d1439c 100644 --- a/Signal/src/util/Backup/OWSBackupImportJob.m +++ b/Signal/src/util/Backup/OWSBackupImportJob.m @@ -134,15 +134,19 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe OWSAssertDebug(self.databaseItems); OWSAssertDebug(self.attachmentsItems); + // These items should be downloaded immediately. NSMutableArray *allItems = [NSMutableArray new]; [allItems addObjectsFromArray:self.databaseItems]; if (self.manifest.localProfileAvatarItem) { [allItems addObject:self.manifest.localProfileAvatarItem]; } - // Attachments can be downloaded later; - // - NSArray *eagerItems = [allItems copy]; + // Make a copy of the blockingItems before we add + // the attachment items. + NSArray *blockingItems = [allItems copy]; + + // Attachment items can be downloaded later; + // they will can be lazy-restored. [allItems addObjectsFromArray:self.attachmentsItems]; // Record metadata for all items, so that we can re-use them in incremental backups after the restore. @@ -152,7 +156,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe } }]; - return [self downloadFilesFromCloud:eagerItems] + return [self downloadFilesFromCloud:blockingItems] .thenInBackground(^{ return [self restoreDatabase]; }) @@ -253,7 +257,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe - (AnyPromise *)restoreLocalProfile { - OWSLogVerbose(@": %zd", self.attachmentsItems.count); + OWSLogVerbose(@""); if (self.isComplete) { // Job was aborted. @@ -266,12 +270,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe if (self.manifest.localProfileAvatarItem) { OWSBackupFragment *item = self.manifest.localProfileAvatarItem; if (item.recordName.length < 1) { - OWSLogError(@"local profile avatar was not downloaded."); - // Ignore errors related to local profile. - return [AnyPromise promiseWithValue:@(1)]; - } - if (!item.uncompressedDataLength || item.uncompressedDataLength.unsignedIntValue < 1) { - OWSLogError(@"database snapshot missing size."); + OWSLogError(@"item was not downloaded."); // Ignore errors related to local profile. return [AnyPromise promiseWithValue:@(1)]; } @@ -295,6 +294,8 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe } } + OWSLogVerbose(@"local profile name: %@, avatar: %d", localProfileName, localProfileAvatar != nil); + if (localProfileName.length > 0 || localProfileAvatar) { AnyPromise *promise = [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) { [self.profileManager updateLocalProfileName:localProfileName