зеркало из https://github.com/nextcloud/desktop.git
Move parentItemIdentifierMetadata helper method to the database manager
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Родитель
3ec9968fc2
Коммит
1d1578447e
|
@ -297,6 +297,26 @@ class NextcloudFilesDatabaseManager : NSObject {
|
|||
}
|
||||
}
|
||||
|
||||
func parentItemIdentifierFromMetadata(_ metadata: NextcloudItemMetadataTable) -> NSFileProviderItemIdentifier? {
|
||||
let homeServerFilesUrl = metadata.urlBase + "/remote.php/dav/files/" + metadata.userId
|
||||
|
||||
if metadata.serverUrl == homeServerFilesUrl {
|
||||
return .rootContainer
|
||||
}
|
||||
|
||||
guard let itemParentDirectory = parentDirectoryMetadataForItem(metadata) else {
|
||||
NSLog("Could not get item parent directory metadata for metadata with ocId: %@ and fileName: %@, returning nil", metadata.ocId, metadata.fileName)
|
||||
return nil
|
||||
}
|
||||
|
||||
if let parentDirectoryMetadata = itemMetadataFromOcId(itemParentDirectory.ocId) {
|
||||
return NSFileProviderItemIdentifier(parentDirectoryMetadata.ocId)
|
||||
}
|
||||
|
||||
NSLog("Could not get item parent directory item metadata for metadata with ocId: %@ and fileName: %@, returning nil", metadata.ocId, metadata.fileName)
|
||||
return nil
|
||||
}
|
||||
|
||||
func directoryMetadata(account: String, serverUrl: String) -> NextcloudDirectoryMetadataTable? {
|
||||
if let metadata = ncDatabase().objects(NextcloudDirectoryMetadataTable.self).filter("account == %@ AND serverUrl == %@", account, serverUrl).first {
|
||||
return NextcloudDirectoryMetadataTable(value: metadata)
|
||||
|
|
|
@ -284,7 +284,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
|||
createFileOrDirectoryLocally(metadata: itemMetadata)
|
||||
}
|
||||
|
||||
if let parentItemIdentifier = parentItemIdentifierFromMetadata(itemMetadata) {
|
||||
if let parentItemIdentifier = NextcloudFilesDatabaseManager.shared.parentItemIdentifierFromMetadata(itemMetadata) {
|
||||
let item = FileProviderItem(metadata: itemMetadata, parentItemIdentifier: parentItemIdentifier, ncKit: ncKit)
|
||||
NSLog("Will enumerate item with ocId: %@ and name: %@", itemMetadata.ocId, itemMetadata.fileName)
|
||||
items.append(item)
|
||||
|
@ -337,7 +337,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
|||
var allFpItemDeletionsIdentifiers = Array(allDeletedMetadatas.map { NSFileProviderItemIdentifier($0.ocId) })
|
||||
|
||||
for updMetadata in allUpdatedMetadatas {
|
||||
guard let parentItemIdentifier = parentItemIdentifierFromMetadata(updMetadata) else {
|
||||
guard let parentItemIdentifier = NextcloudFilesDatabaseManager.shared.parentItemIdentifierFromMetadata(updMetadata) else {
|
||||
NSLog("Not enumerating change for metadata: %@ %@ as could not get parent item metadata.", updMetadata.ocId, updMetadata.fileName)
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
|||
let dbManager = NextcloudFilesDatabaseManager.shared
|
||||
|
||||
guard let metadata = dbManager.itemMetadataFromFileProviderItemIdentifier(identifier),
|
||||
let parentItemIdentifier = parentItemIdentifierFromMetadata(metadata) else {
|
||||
let parentItemIdentifier = dbManager.parentItemIdentifierFromMetadata(metadata) else {
|
||||
completionHandler(nil, NSFileProviderError(.noSuchItem))
|
||||
return Progress()
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
|||
dbManager.addLocalFileMetadataFromItemMetadata(updatedMetadata)
|
||||
dbManager.addItemMetadata(updatedMetadata)
|
||||
|
||||
guard let parentItemIdentifier = parentItemIdentifierFromMetadata(updatedMetadata) else {
|
||||
guard let parentItemIdentifier = dbManager.parentItemIdentifierFromMetadata(updatedMetadata) else {
|
||||
completionHandler(nil, nil, NSFileProviderError(.noSuchItem))
|
||||
return
|
||||
}
|
||||
|
|
|
@ -89,27 +89,6 @@ func createFileOrDirectoryLocally(metadata: NextcloudItemMetadataTable) {
|
|||
}
|
||||
}
|
||||
|
||||
func parentItemIdentifierFromMetadata(_ metadata: NextcloudItemMetadataTable) -> NSFileProviderItemIdentifier? {
|
||||
let homeServerFilesUrl = metadata.urlBase + "/remote.php/dav/files/" + metadata.userId
|
||||
|
||||
if metadata.serverUrl == homeServerFilesUrl {
|
||||
return .rootContainer
|
||||
}
|
||||
|
||||
let ncDatabase = NextcloudFilesDatabaseManager.shared
|
||||
guard let itemParentDirectory = ncDatabase.parentDirectoryMetadataForItem(metadata) else {
|
||||
NSLog("Could not get item parent directory metadata for metadata with ocId: %@ and fileName: %@, returning nil", metadata.ocId, metadata.fileName)
|
||||
return nil
|
||||
}
|
||||
|
||||
if let parentDirectoryMetadata = ncDatabase.itemMetadataFromOcId(itemParentDirectory.ocId) {
|
||||
return NSFileProviderItemIdentifier(parentDirectoryMetadata.ocId)
|
||||
}
|
||||
|
||||
NSLog("Could not get item parent directory item metadata for metadata with ocId: %@ and fileName: %@, returning nil", metadata.ocId, metadata.fileName)
|
||||
return nil
|
||||
}
|
||||
|
||||
func isFileSynced(metadata: NextcloudItemMetadataTable) -> Bool {
|
||||
guard metadata.directory else { return false }
|
||||
do {
|
||||
|
|
Загрузка…
Ссылка в новой задаче