Fix local profile restore.

pull/1/head
Matthew Chen 6 years ago
parent 894fd1379c
commit cb349ad0fe

@ -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<String> {
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)

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

@ -134,15 +134,19 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
OWSAssertDebug(self.databaseItems);
OWSAssertDebug(self.attachmentsItems);
// These items should be downloaded immediately.
NSMutableArray<OWSBackupFragment *> *allItems = [NSMutableArray new];
[allItems addObjectsFromArray:self.databaseItems];
if (self.manifest.localProfileAvatarItem) {
[allItems addObject:self.manifest.localProfileAvatarItem];
}
// Attachments can be downloaded later;
//
NSArray<OWSBackupFragment *> *eagerItems = [allItems copy];
// Make a copy of the blockingItems before we add
// the attachment items.
NSArray<OWSBackupFragment *> *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

Loading…
Cancel
Save