Fix path handling for file provider database setup

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-01-26 23:10:43 +01:00
parent e7e985f355
commit f01b6a545f
No known key found for this signature in database
GPG key ID: C839200C384636B0

View file

@ -22,8 +22,8 @@ class NextcloudFilesDatabaseManager : NSObject {
return NextcloudFilesDatabaseManager(); return NextcloudFilesDatabaseManager();
}() }()
let relativeDatabaseFolderPath: String = "Database/" let relativeDatabaseFolderPath = "Database/"
let databaseFilename: String = "fileproviderextdatabase.realm" let databaseFilename = "fileproviderextdatabase.realm"
let relativeDatabaseFilePath: String let relativeDatabaseFilePath: String
var databasePath: URL? var databasePath: URL?
@ -37,15 +37,17 @@ class NextcloudFilesDatabaseManager : NSObject {
return return
} }
self.databasePath = fileProviderDataDirUrl.appendingPathExtension(self.relativeDatabaseFilePath) self.databasePath = fileProviderDataDirUrl.appendingPathComponent(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
let folderPath = fileProviderDataDirUrl.appendingPathComponent(self.relativeDatabaseFolderPath).path let dbFolder = fileProviderDataDirUrl.appendingPathComponent(self.relativeDatabaseFolderPath)
let dbFolderPath = dbFolder.path
do { do {
try FileManager.default.setAttributes([FileAttributeKey.protectionKey: FileProtectionType.completeUntilFirstUserAuthentication], ofItemAtPath: folderPath) try FileManager.default.createDirectory(at: dbFolder, withIntermediateDirectories: true)
} catch { try FileManager.default.setAttributes([FileAttributeKey.protectionKey: FileProtectionType.completeUntilFirstUserAuthentication], ofItemAtPath: dbFolderPath)
NSLog("Could not set permission level for File Provider database folder") } catch let error {
NSLog("Could not set permission level for File Provider database folder, received error: %@", error.localizedDescription)
} }
let config = Realm.Configuration( let config = Realm.Configuration(