Don't open database from app extension

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Marcel Müller 2021-01-07 11:06:15 +01:00
Родитель 11ce777e55
Коммит 6b118b664b
3 изменённых файлов: 50 добавлений и 19 удалений

Просмотреть файл

@ -70,13 +70,20 @@ uint64_t const kTalkDatabaseSchemaVersion = 10;
NSURL *databaseURL = [[NSURL fileURLWithPath:path] URLByAppendingPathComponent:kTalkDatabaseFileName];
if ([[NSFileManager defaultManager] fileExistsAtPath:databaseURL.path]) {
NSError *error = nil;
uint64_t currentDbVersion = [RLMRealm schemaVersionAtURL:databaseURL encryptionKey:nil error:&error];
if (error) {
NSLog(@"Error reading schemaVersion: %@", error.description);
} else {
NSLog(@"Current schemaVersion is %llu app schemaVersion is %llu", currentDbVersion, kTalkDatabaseSchemaVersion);
@try {
NSError *error = nil;
// schemaVersionAtURL throws an exception when file is not readable
uint64_t currentSchemaVersion = [RLMRealm schemaVersionAtURL:databaseURL encryptionKey:nil error:&error];
if (error) {
NSLog(@"Reading schemaVersion failed: %@", error.description);
} else {
NSLog(@"Current schemaVersion is %llu app schemaVersion is %llu", currentSchemaVersion, kTalkDatabaseSchemaVersion);
}
}
@catch (NSException *exception) {
NSLog(@"Reading schemaVersion failed: %@", exception.reason);
}
}

Просмотреть файл

@ -50,12 +50,24 @@
NSURL *databaseURL = [[NSURL fileURLWithPath:path] URLByAppendingPathComponent:kTalkDatabaseFileName];
if ([[NSFileManager defaultManager] fileExistsAtPath:databaseURL.path]) {
NSError *error = nil;
uint64_t currentDbVersion = [RLMRealm schemaVersionAtURL:databaseURL encryptionKey:nil error:&error];
if (error || currentDbVersion != kTalkDatabaseSchemaVersion) {
NSLog(@"Current schemaVersion is %llu app schemaVersion is %llu", currentDbVersion, kTalkDatabaseSchemaVersion);
NSLog(@"Database needs migration -> don't open database from extension");
@try {
NSError *error = nil;
// schemaVersionAtURL throws an exception when file is not readable
uint64_t currentSchemaVersion = [RLMRealm schemaVersionAtURL:databaseURL encryptionKey:nil error:&error];
if (error || currentSchemaVersion != kTalkDatabaseSchemaVersion) {
NSLog(@"Current schemaVersion is %llu app schemaVersion is %llu", currentSchemaVersion, kTalkDatabaseSchemaVersion);
NSLog(@"Database needs migration -> don't open database from extension");
self.contentHandler(self.bestAttemptContent);
return;
} else {
NSLog(@"Current schemaVersion is %llu app schemaVersion is %llu", currentSchemaVersion, kTalkDatabaseSchemaVersion);
}
}
@catch (NSException *exception) {
NSLog(@"Reading schemaVersion failed: %@", exception.reason);
self.contentHandler(self.bestAttemptContent);
return;
}

Просмотреть файл

@ -64,13 +64,25 @@
NSURL *databaseURL = [[NSURL fileURLWithPath:path] URLByAppendingPathComponent:kTalkDatabaseFileName];
if ([[NSFileManager defaultManager] fileExistsAtPath:databaseURL.path]) {
NSError *error = nil;
uint64_t currentDbVersion = [RLMRealm schemaVersionAtURL:databaseURL encryptionKey:nil error:&error];
if (error || currentDbVersion != kTalkDatabaseSchemaVersion) {
NSLog(@"Current schemaVersion is %llu app schemaVersion is %llu", currentDbVersion, kTalkDatabaseSchemaVersion);
NSLog(@"Database needs migration -> don't open database from extension");
@try {
NSError *error = nil;
// schemaVersionAtURL throws an exception when file is not readable
uint64_t currentSchemaVersion = [RLMRealm schemaVersionAtURL:databaseURL encryptionKey:nil error:&error];
if (error || currentSchemaVersion != kTalkDatabaseSchemaVersion) {
NSLog(@"Current schemaVersion is %llu app schemaVersion is %llu", currentSchemaVersion, kTalkDatabaseSchemaVersion);
NSLog(@"Database needs migration -> don't open database from extension");
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil];
[self.extensionContext cancelRequestWithError:error];
return;
} else {
NSLog(@"Current schemaVersion is %llu app schemaVersion is %llu", currentSchemaVersion, kTalkDatabaseSchemaVersion);
}
}
@catch (NSException *exception) {
NSLog(@"Reading schemaVersion failed: %@", exception.reason);
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil];
[self.extensionContext cancelRequestWithError:error];
return;