Rename NextcloudFileMetadataTable to NextcloudItemMetadataTable to more accurately match functionality

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-01-12 21:16:49 +01:00
parent 9ff66bb94f
commit f15187c8b4
No known key found for this signature in database
GPG key ID: C839200C384636B0
3 changed files with 23 additions and 23 deletions

View file

@ -54,8 +54,8 @@ func pathForFileProviderExtFiles() -> URL? {
return try localPathForNCDirectory(ocId: ocId)
}
@discardableResult func localPathForNCDirectory(fileMetadata: NextcloudFileMetadataTable) throws -> URL {
let ocId = fileMetadata.ocId
@discardableResult func localPathForNCDirectory(itemMetadata: NextcloudItemMetadataTable) throws -> URL {
let ocId = itemMetadata.ocId
return try localPathForNCDirectory(ocId: ocId)
}
@ -71,44 +71,45 @@ func pathForFileProviderExtFiles() -> URL? {
return filePathUrl
}
@discardableResult func localPathForNCFile(fileMetadata: NextcloudFileMetadataTable) throws -> URL {
let ocId = fileMetadata.ocId
let fileNameView = fileMetadata.fileNameView
@discardableResult func localPathForNCFile(itemMetadata: NextcloudItemMetadataTable) throws -> URL {
let ocId = itemMetadata.ocId
let fileNameView = itemMetadata.fileNameView
return try localPathForNCFile(ocId: ocId, fileNameView: fileNameView)
}
func createFileOrDirectoryLocally(metadata: NextcloudFileMetadataTable) {
func createFileOrDirectoryLocally(metadata: NextcloudItemMetadataTable) {
do {
if metadata.directory {
try localPathForNCDirectory(ocId: metadata.ocId)
} else {
try localPathForNCFile(fileMetadata: metadata)
try localPathForNCFile(itemMetadata: metadata)
}
} catch let error {
print("Could not create NC file or directory locally, received error: %@", error)
}
}
func parentItemIdentifierFromMetadata(_ metadata: NextcloudFileMetadataTable) -> NSFileProviderItemIdentifier? {
func parentItemIdentifierFromMetadata(_ metadata: NextcloudItemMetadataTable) -> NSFileProviderItemIdentifier? {
let homeServerFilesUrl = metadata.urlBase + "/remote.php/dav/files/" + metadata.userId
let ncDatabase = NextcloudFilesDatabaseManager.shared
guard let itemParentDirectory = ncDatabase.directoryMetadataForFile(metadata) else { return nil }
guard let itemParentDirectory = ncDatabase.parentDirectoryMetadataForItem(metadata) else { return nil }
if itemParentDirectory.serverUrl == homeServerFilesUrl {
return .rootContainer
} else if let parentDirectoryMetadata = ncDatabase.fileMetadataFromOcId(itemParentDirectory.ocId) {
} else if let parentDirectoryMetadata = ncDatabase.itemMetadataFromOcId(itemParentDirectory.ocId) {
return NSFileProviderItemIdentifier(parentDirectoryMetadata.ocId)
}
return nil
}
func isFileSynced(metadata: NextcloudFileMetadataTable) -> Bool {
func isFileSynced(metadata: NextcloudItemMetadataTable) -> Bool {
guard metadata.directory else { return false }
do {
let localPathForFile = try localPathForNCFile(fileMetadata: metadata)
let localPathForFile = try localPathForNCFile(itemMetadata: metadata)
let localFileAttributes = try FileManager.default.attributesOfItem(atPath: localPathForFile.path)
let localFileSize = localFileAttributes[.size] as? Int64
return localFileSize == metadata.size
} catch let error {
print("Could not check if file %@ is synced, received error: %@", metadata.fileNameView, error)

View file

@ -50,7 +50,7 @@ class NextcloudFilesDatabaseManager : NSObject {
let config = Realm.Configuration(
fileURL: self.databasePath,
schemaVersion: self.schemaVersion,
objectTypes: [NextcloudFileMetadataTable.self]
objectTypes: [NextcloudItemMetadataTable.self]
)
Realm.Configuration.defaultConfiguration = config
@ -71,17 +71,16 @@ class NextcloudFilesDatabaseManager : NSObject {
return realm
}
func fileMetadataFromOcId(_ ocId: String) -> NextcloudFileMetadataTable? {
return ncDatabase().objects(NextcloudFileMetadataTable.self).filter("ocId == %@", ocId).first
func itemMetadataFromOcId(_ ocId: String) -> NextcloudItemMetadataTable? {
return ncDatabase().objects(NextcloudItemMetadataTable.self).filter("ocId == %@", ocId).first
}
func fileMetadataFromFileProviderItemIdentifier(_ identifier: NSFileProviderItemIdentifier) -> NextcloudFileMetadataTable? {
func itemMetadataFromFileProviderItemIdentifier(_ identifier: NSFileProviderItemIdentifier) -> NextcloudItemMetadataTable? {
let ocId = identifier.rawValue
return fileMetadataFromOcId(ocId)
return itemMetadataFromOcId(ocId)
}
func directoryMetadataForFile(_ fileMetadata: NextcloudFileMetadataTable) -> NextcloudDirectoryMetadataTable? {
return ncDatabase().objects(NextcloudDirectoryMetadataTable.self).filter("account == %@ AND serverUrl == %@", fileMetadata.account, fileMetadata.serverUrl).first
func parentDirectoryMetadataForItem(_ itemMetadata: NextcloudItemMetadataTable) -> NextcloudDirectoryMetadataTable? {
return ncDatabase().objects(NextcloudDirectoryMetadataTable.self).filter("account == %@ AND serverUrl == %@", itemMetadata.account, itemMetadata.serverUrl).first
}
}

View file

@ -15,7 +15,7 @@
import Foundation
import RealmSwift
class NextcloudFileMetadataTable: Object {
class NextcloudItemMetadataTable: Object {
enum Status: Int {
case downloadError = -4
case downloading = -3
@ -31,7 +31,7 @@ class NextcloudFileMetadataTable: Object {
}
override func isEqual(_ object: Any?) -> Bool {
if let object = object as? NextcloudFileMetadataTable {
if let object = object as? NextcloudItemMetadataTable {
return self.fileId == object.fileId &&
self.account == object.account &&
self.path == object.path &&