|
|
@ -743,17 +743,16 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
// this record's metadata.
|
|
|
|
// this record's metadata.
|
|
|
|
// * That this record does in fact exist in our CloudKit database.
|
|
|
|
// * That this record does in fact exist in our CloudKit database.
|
|
|
|
NSString *lastRecordName = [OWSBackupAPI recordNameForPersistentFileWithFileId:attachmentExport.attachmentId];
|
|
|
|
NSString *lastRecordName = [OWSBackupAPI recordNameForPersistentFileWithFileId:attachmentExport.attachmentId];
|
|
|
|
OWSBackupManifestItem *_Nullable lastManifestItem =
|
|
|
|
OWSBackupFragment *_Nullable lastBackupFragment = [OWSBackupFragment fetchObjectWithUniqueID:lastRecordName];
|
|
|
|
[OWSBackupManifestItem fetchObjectWithUniqueID:lastRecordName];
|
|
|
|
if (lastBackupFragment && [self.lastValidRecordNames containsObject:lastRecordName]) {
|
|
|
|
if (lastManifestItem && [self.lastValidRecordNames containsObject:lastRecordName]) {
|
|
|
|
OWSAssert(lastBackupFragment.encryptionKey.length > 0);
|
|
|
|
OWSAssert(lastManifestItem.encryptionKey.length > 0);
|
|
|
|
OWSAssert(lastBackupFragment.relativeFilePath.length > 0);
|
|
|
|
OWSAssert(lastManifestItem.relativeFilePath.length > 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Recycle the metadata from the last backup's manifest.
|
|
|
|
// Recycle the metadata from the last backup's manifest.
|
|
|
|
OWSBackupEncryptedItem *encryptedItem = [OWSBackupEncryptedItem new];
|
|
|
|
OWSBackupEncryptedItem *encryptedItem = [OWSBackupEncryptedItem new];
|
|
|
|
encryptedItem.encryptionKey = lastManifestItem.encryptionKey;
|
|
|
|
encryptedItem.encryptionKey = lastBackupFragment.encryptionKey;
|
|
|
|
attachmentExport.encryptedItem = encryptedItem;
|
|
|
|
attachmentExport.encryptedItem = encryptedItem;
|
|
|
|
attachmentExport.relativeFilePath = lastManifestItem.relativeFilePath;
|
|
|
|
attachmentExport.relativeFilePath = lastBackupFragment.relativeFilePath;
|
|
|
|
|
|
|
|
|
|
|
|
OWSBackupExportItem *exportItem = [OWSBackupExportItem new];
|
|
|
|
OWSBackupExportItem *exportItem = [OWSBackupExportItem new];
|
|
|
|
exportItem.encryptedItem = attachmentExport.encryptedItem;
|
|
|
|
exportItem.encryptedItem = attachmentExport.encryptedItem;
|
|
|
@ -814,12 +813,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
[strongSelf.savedAttachmentItems addObject:exportItem];
|
|
|
|
[strongSelf.savedAttachmentItems addObject:exportItem];
|
|
|
|
|
|
|
|
|
|
|
|
// Immediately save the record metadata to facilitate export resume.
|
|
|
|
// Immediately save the record metadata to facilitate export resume.
|
|
|
|
OWSBackupManifestItem *backupRestoreMetadata = [OWSBackupManifestItem new];
|
|
|
|
OWSBackupFragment *backupFragment = [OWSBackupFragment new];
|
|
|
|
backupRestoreMetadata.recordName = recordName;
|
|
|
|
backupFragment.recordName = recordName;
|
|
|
|
backupRestoreMetadata.encryptionKey = exportItem.encryptedItem.encryptionKey;
|
|
|
|
backupFragment.encryptionKey = exportItem.encryptedItem.encryptionKey;
|
|
|
|
backupRestoreMetadata.relativeFilePath = attachmentExport.relativeFilePath;
|
|
|
|
backupFragment.relativeFilePath = attachmentExport.relativeFilePath;
|
|
|
|
backupRestoreMetadata.uncompressedDataLength = exportItem.uncompressedDataLength;
|
|
|
|
backupFragment.uncompressedDataLength = exportItem.uncompressedDataLength;
|
|
|
|
[backupRestoreMetadata save];
|
|
|
|
[backupFragment save];
|
|
|
|
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ saved attachment: %@ as %@",
|
|
|
|
DDLogVerbose(@"%@ saved attachment: %@ as %@",
|
|
|
|
self.logTag,
|
|
|
|
self.logTag,
|
|
|
@ -992,11 +991,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
// the latest backup export.
|
|
|
|
// the latest backup export.
|
|
|
|
[self.primaryStorage.newDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self.primaryStorage.newDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
NSMutableSet<NSString *> *obsoleteRecordNames = [NSMutableSet new];
|
|
|
|
NSMutableSet<NSString *> *obsoleteRecordNames = [NSMutableSet new];
|
|
|
|
[obsoleteRecordNames addObjectsFromArray:[transaction allKeysInCollection:[OWSBackupManifestItem collection]]];
|
|
|
|
[obsoleteRecordNames addObjectsFromArray:[transaction allKeysInCollection:[OWSBackupFragment collection]]];
|
|
|
|
[obsoleteRecordNames minusSet:activeRecordNames];
|
|
|
|
[obsoleteRecordNames minusSet:activeRecordNames];
|
|
|
|
|
|
|
|
|
|
|
|
[transaction removeObjectsForKeys:obsoleteRecordNames.allObjects
|
|
|
|
[transaction removeObjectsForKeys:obsoleteRecordNames.allObjects inCollection:[OWSBackupFragment collection]];
|
|
|
|
inCollection:[OWSBackupManifestItem collection]];
|
|
|
|
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|