Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent e23773ed2c
commit 1c012e9a23

@ -45,6 +45,10 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{ actionBlock:^{
[DebugUIBackup logBackupRecords]; [DebugUIBackup logBackupRecords];
}]]; }]];
[items addObject:[OWSTableItem itemWithTitle:@"Log CloudKit backup manifests"
actionBlock:^{
[DebugUIBackup logBackupManifests];
}]];
[items addObject:[OWSTableItem itemWithTitle:@"Restore CloudKit backup" [items addObject:[OWSTableItem itemWithTitle:@"Restore CloudKit backup"
actionBlock:^{ actionBlock:^{
[DebugUIBackup tryToImportBackup]; [DebugUIBackup tryToImportBackup];
@ -110,6 +114,19 @@ NS_ASSUME_NONNULL_BEGIN
[OWSBackup.sharedManager logBackupRecords]; [OWSBackup.sharedManager logBackupRecords];
} }
+ (void)logBackupManifests
{
OWSLogInfo(@"logBackupManifests.");
[OWSBackup.sharedManager
allRecipientIdsWithManifestsInCloud:^(NSArray<NSString *> *recipientIds) {
OWSLogInfo(@"recipientIds: %@", recipientIds);
}
failure:^(NSError *error) {
OWSLogError(@"error: %@", error);
}];
}
+ (void)tryToImportBackup + (void)tryToImportBackup
{ {
OWSLogInfo(@"tryToImportBackup."); OWSLogInfo(@"tryToImportBackup.");

@ -170,7 +170,7 @@ NSString *NSStringForBackupImportState(OWSBackupState state)
} }
if (!self.tsAccountManager.isRegisteredAndReady) { if (!self.tsAccountManager.isRegisteredAndReady) {
OWSLogError(@"Can't backup; not registered and ready."); OWSFailDebug(@"Can't backup; not registered and ready.");
return; return;
} }
NSString *_Nullable recipientId = self.tsAccountManager.localNumber; NSString *_Nullable recipientId = self.tsAccountManager.localNumber;

@ -93,7 +93,7 @@ import CloudKit
} }
private class func recordNamePrefix(forRecipientId recipientId: String) -> String { private class func recordNamePrefix(forRecipientId recipientId: String) -> String {
return "\(recipientId)-" return "\(recipientId)-"
} }
private class func recipientId(forRecordName recordName: String) -> String? { private class func recipientId(forRecordName recordName: String) -> String? {
@ -104,24 +104,31 @@ import CloudKit
return recipientId return recipientId
} }
private static var recordNamePrefixRegex = {
return try! NSRegularExpression(pattern: "^(\\+[0-9]+)\\-")
}()
private class func recipientIds(forRecordNames recordNames: [String]) -> [String] { 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]() var recipientIds = [String]()
for recordName in recordNames { 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.numberOfRanges > 0 else {
// Match must include first group.
Logger.warn("invalid match: \(recordName)")
continue continue
} }
guard match.range.location == 0 else { let firstRange = match.range(at: 1)
// Match must be at start of string. 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 continue
} }
let recipientId = (recordName as NSString).substring(with: match.range) as String let recipientId = (recordName as NSString).substring(with: firstRange) as String
recipientIds.append(recipientId) recipientIds.append(recipientId)
} }
return recipientIds return recipientIds
@ -458,28 +465,6 @@ import CloudKit
failure: failure) 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?, private class func fetchAllRecordNamesStep(recipientId: String?,
query: CKQuery, query: CKQuery,
previousRecordNames: [String], previousRecordNames: [String],

Loading…
Cancel
Save