Page MenuHomePhabricator

D3993.id12732.diff
No OneTemporary

D3993.id12732.diff

diff --git a/native/ios/Comm/AppDelegate.mm b/native/ios/Comm/AppDelegate.mm
--- a/native/ios/Comm/AppDelegate.mm
+++ b/native/ios/Comm/AppDelegate.mm
@@ -19,6 +19,8 @@
#import "NetworkModule.h"
#import "SQLiteQueryExecutor.h"
#import "Tools.h"
+#import <cstdio>
+#import <stdexcept>
#import <string>
#ifdef FB_SONARKIT_ENABLED
@@ -232,6 +234,23 @@
- (void)attemptDatabaseInitialization {
std::string sqliteFilePath =
std::string([[Tools getSQLiteFilePath] UTF8String]);
+
+ // Previous versions of Comm app used to keep SQLite database at location
+ // that was specific to the app. Now that we share SQLite database with
+ // NotificationService extension we need to keep the database in place
+ // defined by App Groups. The code below is a migration fired if user
+ // upgrades from version using app-specific path to newer that uses
+ // App Groups.
+ NSString *appSpecificSQLiteFilePath = [Tools getAppSpecificSQLiteFilePath];
+ if ([NSFileManager.defaultManager
+ fileExistsAtPath:appSpecificSQLiteFilePath] &&
+ std::rename(
+ std::string([appSpecificSQLiteFilePath UTF8String]).c_str(),
+ sqliteFilePath.c_str())) {
+ throw std::runtime_error(
+ "Failed to move SQLite database from app-specific to app group "
+ "location");
+ }
comm::SQLiteQueryExecutor::initialize(sqliteFilePath);
}
diff --git a/native/ios/Comm/Tools.h b/native/ios/Comm/Tools.h
--- a/native/ios/Comm/Tools.h
+++ b/native/ios/Comm/Tools.h
@@ -3,5 +3,6 @@
#import <UIKit/UIKit.h>
@interface Tools : NSObject
++ (NSString *)getAppSpecificSQLiteFilePath;
+ (NSString *)getSQLiteFilePath;
@end
diff --git a/native/ios/Comm/Tools.mm b/native/ios/Comm/Tools.mm
--- a/native/ios/Comm/Tools.mm
+++ b/native/ios/Comm/Tools.mm
@@ -5,6 +5,16 @@
@implementation Tools
+ (NSString *)getSQLiteFilePath {
+ NSURL *groupUrl = [NSFileManager.defaultManager
+ containerURLForSecurityApplicationGroupIdentifier:@"group.app.comm"];
+ if (groupUrl == nil) {
+ throw std::runtime_error(
+ "Failed to resolve database path - could not find groupUrl");
+ }
+ return [groupUrl URLByAppendingPathComponent:@"comm.sqlite"].path;
+}
+
++ (NSString *)getAppSpecificSQLiteFilePath {
NSError *err = nil;
NSURL *documentsUrl =
[NSFileManager.defaultManager URLForDirectory:NSDocumentDirectory

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 7:54 AM (19 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2698116
Default Alt Text
D3993.id12732.diff (2 KB)

Event Timeline