Use pathForFileProviderExtData in NextcloudFilesDatabaseManager

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-01-12 16:51:44 +01:00
parent 730c30f324
commit 83230baeaa
No known key found for this signature in database
GPG key ID: C839200C384636B0

View file

@ -21,7 +21,7 @@ class NextcloudFilesDatabaseManager : NSObject {
return NextcloudFilesDatabaseManager(); return NextcloudFilesDatabaseManager();
}() }()
let relativeDatabaseFolderPath: String = "FileProviderExt/Database/" let relativeDatabaseFolderPath: String = "Database/"
let databaseFilename: String = "fileproviderextdatabase.realm" let databaseFilename: String = "fileproviderextdatabase.realm"
let relativeDatabaseFilePath: String let relativeDatabaseFilePath: String
var databasePath: URL? var databasePath: URL?
@ -31,24 +31,21 @@ class NextcloudFilesDatabaseManager : NSObject {
override init() { override init() {
self.relativeDatabaseFilePath = self.relativeDatabaseFolderPath + self.databaseFilename self.relativeDatabaseFilePath = self.relativeDatabaseFolderPath + self.databaseFilename
guard let appGroupIdentifier = Bundle.main.object(forInfoDictionaryKey: "SocketApiPrefix") as? String else { guard let fileProviderDataDirUrl = pathForFileProviderExtData() else {
super.init() super.init()
return return
} }
let containerUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier) self.databasePath = fileProviderDataDirUrl.appendingPathExtension(self.relativeDatabaseFilePath)
self.databasePath = containerUrl?.appendingPathExtension(self.relativeDatabaseFilePath)
// Disable file protection for directory DB // Disable file protection for directory DB
// https://docs.mongodb.com/realm/sdk/ios/examples/configure-and-open-a-realm/#std-label-ios-open-a-local-realm // https://docs.mongodb.com/realm/sdk/ios/examples/configure-and-open-a-realm/#std-label-ios-open-a-local-realm
if let folderPathURL = containerUrl?.appendingPathComponent(self.relativeDatabaseFolderPath) { let folderPath = fileProviderDataDirUrl.appendingPathComponent(self.relativeDatabaseFolderPath).path
let folderPath = folderPathURL.path
do { do {
try FileManager.default.setAttributes([FileAttributeKey.protectionKey: FileProtectionType.completeUntilFirstUserAuthentication], ofItemAtPath: folderPath) try FileManager.default.setAttributes([FileAttributeKey.protectionKey: FileProtectionType.completeUntilFirstUserAuthentication], ofItemAtPath: folderPath)
} catch { } catch {
print("Could not set permission level for File Provider database folder") print("Could not set permission level for File Provider database folder")
} }
}
let config = Realm.Configuration( let config = Realm.Configuration(
fileURL: self.databasePath, fileURL: self.databasePath,