|
|
|
@ -500,18 +500,18 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
[ext enumerateKeysAndObjectsInGroup:TSLazyRestoreAttachmentsGroup
|
|
|
|
|
usingBlock:^(
|
|
|
|
|
NSString *collection, NSString *key, id object, NSUInteger index, BOOL *stop) {
|
|
|
|
|
if (![object isKindOfClass:[TSAttachmentStream class]]) {
|
|
|
|
|
if (![object isKindOfClass:[TSAttachmentPointer class]]) {
|
|
|
|
|
OWSFailDebug(
|
|
|
|
|
@"Unexpected object: %@ in collection:%@", [object class], collection);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TSAttachmentStream *attachmentStream = object;
|
|
|
|
|
if (!attachmentStream.lazyRestoreFragment) {
|
|
|
|
|
TSAttachmentPointer *attachmentPointer = object;
|
|
|
|
|
if (!attachmentPointer.lazyRestoreFragment) {
|
|
|
|
|
OWSFailDebug(
|
|
|
|
|
@"Invalid object: %@ in collection:%@", [object class], collection);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
[recordNames addObject:attachmentStream.lazyRestoreFragment.recordName];
|
|
|
|
|
[recordNames addObject:attachmentPointer.lazyRestoreFragment.recordName];
|
|
|
|
|
}];
|
|
|
|
|
}];
|
|
|
|
|
return recordNames;
|
|
|
|
@ -535,7 +535,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
return attachmentIds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)lazyRestoreAttachment:(TSAttachmentStream *)attachment
|
|
|
|
|
- (void)lazyRestoreAttachment:(TSAttachmentPointer *)attachment
|
|
|
|
|
backupIO:(OWSBackupIO *)backupIO
|
|
|
|
|
completion:(OWSBackupBoolBlock)completion
|
|
|
|
|
{
|
|
|
|
@ -543,16 +543,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
OWSAssertDebug(backupIO);
|
|
|
|
|
OWSAssertDebug(completion);
|
|
|
|
|
|
|
|
|
|
NSString *_Nullable attachmentFilePath = [attachment originalFilePath];
|
|
|
|
|
if (attachmentFilePath.length < 1) {
|
|
|
|
|
OWSLogError(@"Attachment has invalid file path.");
|
|
|
|
|
return completion(NO);
|
|
|
|
|
}
|
|
|
|
|
if ([NSFileManager.defaultManager fileExistsAtPath:attachmentFilePath]) {
|
|
|
|
|
OWSLogError(@"Attachment already has file.");
|
|
|
|
|
return completion(NO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OWSBackupFragment *_Nullable lazyRestoreFragment = attachment.lazyRestoreFragment;
|
|
|
|
|
if (!lazyRestoreFragment) {
|
|
|
|
|
OWSLogWarn(@"Attachment missing lazy restore metadata.");
|
|
|
|
@ -587,13 +577,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)lazyRestoreAttachment:(TSAttachmentStream *)attachment
|
|
|
|
|
- (void)lazyRestoreAttachment:(TSAttachmentPointer *)attachmentPointer
|
|
|
|
|
backupIO:(OWSBackupIO *)backupIO
|
|
|
|
|
encryptedFilePath:(NSString *)encryptedFilePath
|
|
|
|
|
encryptionKey:(NSData *)encryptionKey
|
|
|
|
|
completion:(OWSBackupBoolBlock)completion
|
|
|
|
|
{
|
|
|
|
|
OWSAssertDebug(attachment);
|
|
|
|
|
OWSAssertDebug(attachmentPointer);
|
|
|
|
|
OWSAssertDebug(backupIO);
|
|
|
|
|
OWSAssertDebug(encryptedFilePath.length > 0);
|
|
|
|
|
OWSAssertDebug(encryptionKey.length > 0);
|
|
|
|
@ -614,7 +604,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSString *_Nullable attachmentFilePath = [attachment originalFilePath];
|
|
|
|
|
TSAttachmentStream *stream = [[TSAttachmentStream alloc] initWithPointer:attachmentPointer];
|
|
|
|
|
|
|
|
|
|
NSString *attachmentFilePath = stream.originalFilePath;
|
|
|
|
|
if (attachmentFilePath.length < 1) {
|
|
|
|
|
OWSLogError(@"Attachment has invalid file path.");
|
|
|
|
|
return completion(NO);
|
|
|
|
@ -634,7 +626,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
return completion(NO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[attachment updateWithLazyRestoreComplete];
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
// This should overwrite the attachment pointer with an attachment stream.
|
|
|
|
|
[stream saveWithTransaction:transaction];
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
completion(YES);
|
|
|
|
|
}
|
|
|
|
|