Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3522863
D3993.id12720.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D3993.id12720.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 7:48 AM (20 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2698116
Default Alt Text
D3993.id12720.diff (2 KB)
Attached To
Mode
D3993: Make App Groups SQLite path a default one. Implement migration from previous path
Attached
Detach File
Event Timeline
Log In to Comment