Respond to CR.
This commit is contained in:
parent
e23773ed2c
commit
1c012e9a23
|
@ -45,6 +45,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
actionBlock:^{
|
||||
[DebugUIBackup logBackupRecords];
|
||||
}]];
|
||||
[items addObject:[OWSTableItem itemWithTitle:@"Log CloudKit backup manifests"
|
||||
actionBlock:^{
|
||||
[DebugUIBackup logBackupManifests];
|
||||
}]];
|
||||
[items addObject:[OWSTableItem itemWithTitle:@"Restore CloudKit backup"
|
||||
actionBlock:^{
|
||||
[DebugUIBackup tryToImportBackup];
|
||||
|
@ -110,6 +114,19 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[OWSBackup.sharedManager logBackupRecords];
|
||||
}
|
||||
|
||||
+ (void)logBackupManifests
|
||||
{
|
||||
OWSLogInfo(@"logBackupManifests.");
|
||||
|
||||
[OWSBackup.sharedManager
|
||||
allRecipientIdsWithManifestsInCloud:^(NSArray<NSString *> *recipientIds) {
|
||||
OWSLogInfo(@"recipientIds: %@", recipientIds);
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
OWSLogError(@"error: %@", error);
|
||||
}];
|
||||
}
|
||||
|
||||
+ (void)tryToImportBackup
|
||||
{
|
||||
OWSLogInfo(@"tryToImportBackup.");
|
||||
|
|
|
@ -170,7 +170,7 @@ NSString *NSStringForBackupImportState(OWSBackupState state)
|
|||
}
|
||||
|
||||
if (!self.tsAccountManager.isRegisteredAndReady) {
|
||||
OWSLogError(@"Can't backup; not registered and ready.");
|
||||
OWSFailDebug(@"Can't backup; not registered and ready.");
|
||||
return;
|
||||
}
|
||||
NSString *_Nullable recipientId = self.tsAccountManager.localNumber;
|
||||
|
|
|
@ -93,7 +93,7 @@ import CloudKit
|
|||
}
|
||||
|
||||
private class func recordNamePrefix(forRecipientId recipientId: String) -> String {
|
||||
return "\(recipientId)-"
|
||||
return "\(recipientId)-"
|
||||
}
|
||||
|
||||
private class func recipientId(forRecordName recordName: String) -> String? {
|
||||
|
@ -104,24 +104,31 @@ import CloudKit
|
|||
return recipientId
|
||||
}
|
||||
|
||||
private static var recordNamePrefixRegex = {
|
||||
return try! NSRegularExpression(pattern: "^(\\+[0-9]+)\\-")
|
||||
}()
|
||||
|
||||
private class func recipientIds(forRecordNames recordNames: [String]) -> [String] {
|
||||
let regex: NSRegularExpression
|
||||
do {
|
||||
regex = try NSRegularExpression(pattern: "(\\+[0-9]+)\\-")
|
||||
} catch {
|
||||
Logger.error("couldn't compile regex: \(error)")
|
||||
return []
|
||||
}
|
||||
var recipientIds = [String]()
|
||||
for recordName in recordNames {
|
||||
guard let match = regex.firstMatch(in: recordName, options: [], range: NSRange(location: 0, length: recordName.count)) else {
|
||||
let regex = recordNamePrefixRegex
|
||||
guard let match: NSTextCheckingResult = regex.firstMatch(in: recordName, options: [], range: NSRange(location: 0, length: recordName.count)) else {
|
||||
Logger.warn("no match: \(recordName)")
|
||||
continue
|
||||
}
|
||||
guard match.range.location == 0 else {
|
||||
// Match must be at start of string.
|
||||
guard match.numberOfRanges > 0 else {
|
||||
// Match must include first group.
|
||||
Logger.warn("invalid match: \(recordName)")
|
||||
continue
|
||||
}
|
||||
let recipientId = (recordName as NSString).substring(with: match.range) as String
|
||||
let firstRange = match.range(at: 1)
|
||||
guard firstRange.location == 0,
|
||||
firstRange.length > 0 else {
|
||||
// Match must be at start of string and non-empty.
|
||||
Logger.warn("invalid match: \(recordName) \(firstRange)")
|
||||
continue
|
||||
}
|
||||
let recipientId = (recordName as NSString).substring(with: firstRange) as String
|
||||
recipientIds.append(recipientId)
|
||||
}
|
||||
return recipientIds
|
||||
|
@ -458,28 +465,6 @@ import CloudKit
|
|||
failure: failure)
|
||||
}
|
||||
|
||||
// @objc
|
||||
// public class func fetchAllBackupRecipientIds(success: @escaping ([String]) -> Void,
|
||||
// failure: @escaping (Error) -> Void) {
|
||||
//
|
||||
// let processResults = { (recordNames: [String]) in
|
||||
// DispatchQueue.global().async {
|
||||
// let recipientIds = self.recipientIds(forRecordNames: recordNames)
|
||||
// success(recipientIds)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// let query = CKQuery(recordType: signalBackupRecordType, predicate: NSPredicate(value: true))
|
||||
// // Fetch the first page of results for this query.
|
||||
// fetchAllRecordNamesStep(recipientId: nil,
|
||||
// query: query,
|
||||
// previousRecordNames: [String](),
|
||||
// cursor: nil,
|
||||
// remainingRetries: maxRetries,
|
||||
// success: processResults,
|
||||
// failure: failure)
|
||||
// }
|
||||
|
||||
private class func fetchAllRecordNamesStep(recipientId: String?,
|
||||
query: CKQuery,
|
||||
previousRecordNames: [String],
|
||||
|
|
Loading…
Reference in New Issue