mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-25 22:46:04 +03:00
Improve logging in FileProviderEnumerator
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
67de82913e
commit
325878b696
1 changed files with 41 additions and 6 deletions
|
@ -41,6 +41,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSLog("Set up enumerator for user: %@ with serverUrl: %@", ncAccount.username, serverUrl)
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
||||||
// MARK: - Protocol methods
|
// MARK: - Protocol methods
|
||||||
|
|
||||||
func enumerateItems(for observer: NSFileProviderEnumerationObserver, startingAt page: NSFileProviderPage) {
|
func enumerateItems(for observer: NSFileProviderEnumerationObserver, startingAt page: NSFileProviderPage) {
|
||||||
|
NSLog("Received enumerate items request for enumerator with user: %@ with serverUrl: %@", ncAccount.username, serverUrl)
|
||||||
/* TODO:
|
/* TODO:
|
||||||
- inspect the page to determine whether this is an initial or a follow-up request
|
- inspect the page to determine whether this is an initial or a follow-up request
|
||||||
|
|
||||||
|
@ -65,6 +67,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if enumeratedItemIdentifier == .workingSet {
|
if enumeratedItemIdentifier == .workingSet {
|
||||||
|
NSLog("Enumerating working set for user: %@ with serverUrl: %@", ncAccount.username, serverUrl)
|
||||||
// TODO
|
// TODO
|
||||||
observer.finishEnumerating(upTo: nil)
|
observer.finishEnumerating(upTo: nil)
|
||||||
return
|
return
|
||||||
|
@ -73,16 +76,21 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
||||||
if page == NSFileProviderPage.initialPageSortedByDate as NSFileProviderPage ||
|
if page == NSFileProviderPage.initialPageSortedByDate as NSFileProviderPage ||
|
||||||
page == NSFileProviderPage.initialPageSortedByName as NSFileProviderPage {
|
page == NSFileProviderPage.initialPageSortedByName as NSFileProviderPage {
|
||||||
|
|
||||||
|
NSLog("Enumerating initial page for user: %@ with serverUrl: %@", ncAccount.username, serverUrl)
|
||||||
FileProviderEnumerator.readServerUrl(serverUrl, ncAccount: ncAccount) { metadatas in
|
FileProviderEnumerator.readServerUrl(serverUrl, ncAccount: ncAccount) { metadatas in
|
||||||
FileProviderEnumerator.completeObserver(observer, numPage: 1, itemMetadatas: metadatas)
|
FileProviderEnumerator.completeObserver(observer, numPage: 1, itemMetadatas: metadatas)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
let numPage = Int(String(data: page.rawValue, encoding: .utf8)!)!
|
return;
|
||||||
FileProviderEnumerator.completeObserver(observer, numPage: numPage, itemMetadatas: nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let numPage = Int(String(data: page.rawValue, encoding: .utf8)!)!
|
||||||
|
NSLog("Enumerating page %d for user: %@ with serverUrl: %@", numPage, ncAccount.username, serverUrl)
|
||||||
|
FileProviderEnumerator.completeObserver(observer, numPage: numPage, itemMetadatas: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func enumerateChanges(for observer: NSFileProviderChangeObserver, from anchor: NSFileProviderSyncAnchor) {
|
func enumerateChanges(for observer: NSFileProviderChangeObserver, from anchor: NSFileProviderSyncAnchor) {
|
||||||
|
NSLog("Received enumerate changes request for enumerator with user: %@ with serverUrl: %@", ncAccount.username, serverUrl)
|
||||||
/* TODO:
|
/* TODO:
|
||||||
- query the server for updates since the passed-in sync anchor
|
- query the server for updates since the passed-in sync anchor
|
||||||
|
|
||||||
|
@ -102,22 +110,34 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
||||||
// MARK: - Helper methods
|
// MARK: - Helper methods
|
||||||
|
|
||||||
private static func completeObserver(_ observer: NSFileProviderEnumerationObserver, numPage: Int, itemMetadatas: [NextcloudItemMetadataTable]?) {
|
private static func completeObserver(_ observer: NSFileProviderEnumerationObserver, numPage: Int, itemMetadatas: [NextcloudItemMetadataTable]?) {
|
||||||
guard itemMetadatas != nil else { observer.finishEnumerating(upTo: nil); return }
|
guard itemMetadatas != nil else {
|
||||||
|
NSLog("Received nil metadatas, finish empty enumeration")
|
||||||
|
observer.finishEnumerating(upTo: nil)
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
var items: [NSFileProviderItem] = []
|
var items: [NSFileProviderItem] = []
|
||||||
|
|
||||||
for itemMetadata in itemMetadatas! {
|
for itemMetadata in itemMetadatas! {
|
||||||
if itemMetadata.e2eEncrypted { continue }
|
if itemMetadata.e2eEncrypted {
|
||||||
|
NSLog("Skipping encrypted metadata in enumeration")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
createFileOrDirectoryLocally(metadata: itemMetadata)
|
createFileOrDirectoryLocally(metadata: itemMetadata)
|
||||||
|
|
||||||
if let parentItemIdentifier = parentItemIdentifierFromMetadata(itemMetadata) {
|
if let parentItemIdentifier = parentItemIdentifierFromMetadata(itemMetadata) {
|
||||||
let item = FileProviderItem(metadata: itemMetadata, parentItemIdentifier: parentItemIdentifier)
|
let item = FileProviderItem(metadata: itemMetadata, parentItemIdentifier: parentItemIdentifier)
|
||||||
|
NSLog("Will enumerate item with ocId: %@ and name: %@", itemMetadata.ocId, itemMetadata.fileName)
|
||||||
items.append(item)
|
items.append(item)
|
||||||
|
} else {
|
||||||
|
NSLog("Could not get valid parentItemIdentifier for item with ocId: %@ and name: %@, skipping enumeration", itemMetadata.ocId, itemMetadata.fileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
observer.didEnumerate(items)
|
observer.didEnumerate(items)
|
||||||
|
NSLog("Did enumerate %d items", items.count)
|
||||||
|
|
||||||
if items.count == maxItemsPerFileProviderPage {
|
if items.count == maxItemsPerFileProviderPage {
|
||||||
let nextPage = numPage + 1
|
let nextPage = numPage + 1
|
||||||
|
@ -130,6 +150,8 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
||||||
|
|
||||||
private static func finishReadServerUrl(_ serverUrlPath: String, ncKitAccount: String, completionHandler: @escaping (_ metadatas: [NextcloudItemMetadataTable]?) -> Void) {
|
private static func finishReadServerUrl(_ serverUrlPath: String, ncKitAccount: String, completionHandler: @escaping (_ metadatas: [NextcloudItemMetadataTable]?) -> Void) {
|
||||||
let metadatas = NextcloudFilesDatabaseManager.shared.itemMetadatas(account: ncKitAccount, serverUrl: serverUrlPath)
|
let metadatas = NextcloudFilesDatabaseManager.shared.itemMetadatas(account: ncKitAccount, serverUrl: serverUrlPath)
|
||||||
|
|
||||||
|
NSLog("Finished reading serverUrl: %@ for user: %@. Processed %d metadatas", serverUrlPath, ncKitAccount, metadatas.count)
|
||||||
completionHandler(metadatas)
|
completionHandler(metadatas)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,18 +164,31 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
||||||
directoryEtag = directoryMetadata.etag
|
directoryEtag = directoryMetadata.etag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSLog("Starting to read serverUrl: %@ for user: %@ at depth 0", serverUrl, ncKitAccount)
|
||||||
|
|
||||||
NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "0", showHiddenFiles: true) { account, files, _, error in
|
NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "0", showHiddenFiles: true) { account, files, _, error in
|
||||||
guard directoryEtag != files.first?.etag else {
|
guard error == .success else {
|
||||||
|
NSLog("0 depth readFileOrFolder of url: %@ did not complete successfully, received error: %@", serverUrl, error.errorDescription)
|
||||||
finishReadServerUrl(serverUrl, ncKitAccount: ncKitAccount, completionHandler: completionHandler)
|
finishReadServerUrl(serverUrl, ncKitAccount: ncKitAccount, completionHandler: completionHandler)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guard directoryEtag != files.first?.etag else {
|
||||||
|
NSLog("Fetched directory etag is same as that stored locally (serverUrl: %@ user: %@). Not fetching child items.", serverUrl, account)
|
||||||
|
finishReadServerUrl(serverUrl, ncKitAccount: ncKitAccount, completionHandler: completionHandler)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
NSLog("Starting to read serverUrl: %@ for user: %@ at depth 1", serverUrl, ncKitAccount)
|
||||||
|
|
||||||
NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: true) { account, files, _, error in
|
NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: true) { account, files, _, error in
|
||||||
guard error == .success else {
|
guard error == .success else {
|
||||||
|
NSLog("1 depth readFileOrFolder of url: %@ did not complete successfully, received error: %@", serverUrl, error.errorDescription)
|
||||||
finishReadServerUrl(serverUrl, ncKitAccount: ncKitAccount, completionHandler: completionHandler)
|
finishReadServerUrl(serverUrl, ncKitAccount: ncKitAccount, completionHandler: completionHandler)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSLog("Starting async conversion of NKFiles for serverUrl: %@ for user: %@", serverUrl, ncKitAccount)
|
||||||
DispatchQueue.global().async {
|
DispatchQueue.global().async {
|
||||||
dbManager.convertNKFilesToItemMetadatas(files, account: ncKitAccount) { _, childDirectoriesMetadata, metadatas in
|
dbManager.convertNKFilesToItemMetadatas(files, account: ncKitAccount) { _, childDirectoriesMetadata, metadatas in
|
||||||
dbManager.updateItemMetadatas(account: ncKitAccount, serverUrl: serverUrl, updatedMetadatas: metadatas)
|
dbManager.updateItemMetadatas(account: ncKitAccount, serverUrl: serverUrl, updatedMetadatas: metadatas)
|
||||||
|
|
Loading…
Reference in a new issue