]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Add basic NextcloudFilesDatabaseManager for FileProvider files
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 5 Jan 2023 19:59:50 +0000 (20:59 +0100)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 12 May 2023 05:21:10 +0000 (13:21 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudFilesDatabaseManager.swift [new file with mode: 0644]
shell_integration/MacOSX/NextcloudIntegration/NextcloudIntegration.xcodeproj/project.pbxproj

diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudFilesDatabaseManager.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudFilesDatabaseManager.swift
new file mode 100644 (file)
index 0000000..7aa29e0
--- /dev/null
@@ -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()
+    }
+}
index e0e337bbcc0793a3b3393d049f1076d085a0cc27..faa602ad6aadcd684a63e6c04512d2da64460def 100644 (file)
                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 */; };
 /* 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>"; };
                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 */,
                        );
                        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 */,
                        );