mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Add basic NextcloudFilesDatabaseManager for FileProvider files
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
41fe92ebd2
commit
5337d5d654
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2022 by Claudio Cambra <claudio.cambra@nextcloud.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import RealmSwift
|
||||
|
||||
class NextcloudFilesDatabaseManager : NSObject {
|
||||
static let shared = {
|
||||
return NextcloudFilesDatabaseManager();
|
||||
}()
|
||||
|
||||
let relativeDatabaseFolderPath: String = "FileProviderExt/Database/"
|
||||
let databaseFilename: String = "fileproviderextdatabase.realm"
|
||||
let relativeDatabaseFilePath: String
|
||||
var databasePath: URL?
|
||||
|
||||
let schemaVersion: UInt64 = 100
|
||||
var validDatabase: Bool = false
|
||||
|
||||
override init() {
|
||||
self.relativeDatabaseFilePath = self.relativeDatabaseFolderPath + self.databaseFilename
|
||||
|
||||
guard let appGroupIdentifier = Bundle.main.object(forInfoDictionaryKey: "SocketApiPrefix") as? String else {
|
||||
super.init()
|
||||
return
|
||||
}
|
||||
|
||||
let containerUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)
|
||||
self.databasePath = containerUrl?.appendingPathExtension(self.relativeDatabaseFilePath)
|
||||
|
||||
// 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
|
||||
if let folderPathURL = containerUrl?.appendingPathComponent(self.relativeDatabaseFolderPath) {
|
||||
let folderPath = folderPathURL.path
|
||||
do {
|
||||
try FileManager.default.setAttributes([FileAttributeKey.protectionKey: FileProtectionType.completeUntilFirstUserAuthentication], ofItemAtPath: folderPath)
|
||||
} catch {
|
||||
print("Could not set permission level for File Provider database folder")
|
||||
}
|
||||
}
|
||||
|
||||
let config = Realm.Configuration(
|
||||
fileURL: self.databasePath,
|
||||
schemaVersion: self.schemaVersion,
|
||||
objectTypes: [NextcloudFileMetadataTable.self]
|
||||
)
|
||||
|
||||
Realm.Configuration.defaultConfiguration = config
|
||||
|
||||
do {
|
||||
let realm = try Realm()
|
||||
print("Successfully started Realm db for FileProviderExt")
|
||||
self.validDatabase = true
|
||||
} catch let error as NSError {
|
||||
print("Error opening Realm db: %@", error.localizedDescription)
|
||||
}
|
||||
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@ -10,8 +10,10 @@
|
||||
5307A6E62965C6FA001E0C6A /* NextcloudKit in Frameworks */ = {isa = PBXBuildFile; productRef = 5307A6E52965C6FA001E0C6A /* NextcloudKit */; };
|
||||
5307A6E82965DAD8001E0C6A /* NextcloudKit in Frameworks */ = {isa = PBXBuildFile; productRef = 5307A6E72965DAD8001E0C6A /* NextcloudKit */; };
|
||||
5307A6EB2965DB8D001E0C6A /* RealmSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 5307A6EA2965DB8D001E0C6A /* RealmSwift */; };
|
||||
5307A6F029674953001E0C6A /* NextcloudFilesDatabaseTables.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5307A6EF29674953001E0C6A /* NextcloudFilesDatabaseTables.swift */; };
|
||||
5307A6F229675346001E0C6A /* NextcloudFilesDatabaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5307A6F129675346001E0C6A /* NextcloudFilesDatabaseManager.swift */; };
|
||||
536EFBF7295CF58100F4CB13 /* FileProviderSocketLineProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536EFBF6295CF58100F4CB13 /* FileProviderSocketLineProcessor.swift */; };
|
||||
536EFC36295E3C1100F4CB13 /* FileProviderDomainNextcloudAccountData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536EFC35295E3C1100F4CB13 /* FileProviderDomainNextcloudAccountData.swift */; };
|
||||
536EFC36295E3C1100F4CB13 /* NextcloudAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536EFC35295E3C1100F4CB13 /* NextcloudAccount.swift */; };
|
||||
538E396A27F4765000FA63D5 /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 538E396927F4765000FA63D5 /* UniformTypeIdentifiers.framework */; };
|
||||
538E396D27F4765000FA63D5 /* FileProviderExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 538E396C27F4765000FA63D5 /* FileProviderExtension.swift */; };
|
||||
538E396F27F4765000FA63D5 /* FileProviderItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 538E396E27F4765000FA63D5 /* FileProviderItem.swift */; };
|
||||
@ -126,8 +128,10 @@
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
5307A6EF29674953001E0C6A /* NextcloudFilesDatabaseTables.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextcloudFilesDatabaseTables.swift; sourceTree = "<group>"; };
|
||||
5307A6F129675346001E0C6A /* NextcloudFilesDatabaseManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextcloudFilesDatabaseManager.swift; sourceTree = "<group>"; };
|
||||
536EFBF6295CF58100F4CB13 /* FileProviderSocketLineProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderSocketLineProcessor.swift; sourceTree = "<group>"; };
|
||||
536EFC35295E3C1100F4CB13 /* FileProviderDomainNextcloudAccountData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderDomainNextcloudAccountData.swift; sourceTree = "<group>"; };
|
||||
536EFC35295E3C1100F4CB13 /* NextcloudAccount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextcloudAccount.swift; sourceTree = "<group>"; };
|
||||
538E396727F4765000FA63D5 /* FileProviderExt.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = FileProviderExt.appex; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
538E396927F4765000FA63D5 /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
|
||||
538E396C27F4765000FA63D5 /* FileProviderExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderExtension.swift; sourceTree = "<group>"; };
|
||||
@ -208,11 +212,13 @@
|
||||
538E396B27F4765000FA63D5 /* FileProviderExt */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
536EFC35295E3C1100F4CB13 /* FileProviderDomainNextcloudAccountData.swift */,
|
||||
538E397027F4765000FA63D5 /* FileProviderEnumerator.swift */,
|
||||
538E396C27F4765000FA63D5 /* FileProviderExtension.swift */,
|
||||
538E396E27F4765000FA63D5 /* FileProviderItem.swift */,
|
||||
536EFBF6295CF58100F4CB13 /* FileProviderSocketLineProcessor.swift */,
|
||||
536EFC35295E3C1100F4CB13 /* NextcloudAccount.swift */,
|
||||
5307A6F129675346001E0C6A /* NextcloudFilesDatabaseManager.swift */,
|
||||
5307A6EF29674953001E0C6A /* NextcloudFilesDatabaseTables.swift */,
|
||||
538E397327F4765000FA63D5 /* FileProviderExt.entitlements */,
|
||||
538E397227F4765000FA63D5 /* Info.plist */,
|
||||
);
|
||||
@ -519,9 +525,11 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
536EFC36295E3C1100F4CB13 /* FileProviderDomainNextcloudAccountData.swift in Sources */,
|
||||
5307A6F029674953001E0C6A /* NextcloudFilesDatabaseTables.swift in Sources */,
|
||||
536EFC36295E3C1100F4CB13 /* NextcloudAccount.swift in Sources */,
|
||||
538E396D27F4765000FA63D5 /* FileProviderExtension.swift in Sources */,
|
||||
536EFBF7295CF58100F4CB13 /* FileProviderSocketLineProcessor.swift in Sources */,
|
||||
5307A6F229675346001E0C6A /* NextcloudFilesDatabaseManager.swift in Sources */,
|
||||
538E396F27F4765000FA63D5 /* FileProviderItem.swift in Sources */,
|
||||
538E397127F4765000FA63D5 /* FileProviderEnumerator.swift in Sources */,
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user