Skip to content

Commit

Permalink
Merge pull request #15 from claucambra/feature/remove-useless-ncaccou…
Browse files Browse the repository at this point in the history
…nt-use

Remove unnecessary uses of ncaccount in methods
  • Loading branch information
claucambra authored Jul 28, 2024
2 parents acc7b08 + 172302e commit 9890a78
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import OSLog

extension Enumerator {
func fullRecursiveScan(
ncAccount: Account,
remoteInterface: RemoteInterface,
dbManager: FilesDatabaseManager,
scanChangesOnly: Bool
Expand All @@ -35,7 +34,6 @@ extension Enumerator {

let results = await self.scanRecursively(
rootContainerDirectoryMetadata,
ncAccount: ncAccount,
remoteInterface: remoteInterface,
dbManager: dbManager,
scanChangesOnly: scanChangesOnly
Expand Down Expand Up @@ -67,7 +65,6 @@ extension Enumerator {

private func scanRecursively(
_ directoryMetadata: ItemMetadata,
ncAccount: Account,
remoteInterface: RemoteInterface,
dbManager: FilesDatabaseManager,
scanChangesOnly: Bool
Expand All @@ -92,7 +89,7 @@ extension Enumerator {

let itemServerUrl =
directoryMetadata.ocId == NSFileProviderItemIdentifier.rootContainer.rawValue
? ncAccount.davFilesUrl
? remoteInterface.account.davFilesUrl
: directoryMetadata.serverUrl + "/" + directoryMetadata.fileName

Self.logger.debug("About to read: \(itemServerUrl, privacy: .public)")
Expand All @@ -101,7 +98,6 @@ extension Enumerator {
metadatas, newMetadatas, updatedMetadatas, deletedMetadatas, readError
) = await Self.readServerUrl(
itemServerUrl,
ncAccount: ncAccount,
remoteInterface: remoteInterface,
dbManager: dbManager,
domain: domain,
Expand Down Expand Up @@ -160,7 +156,7 @@ extension Enumerator {
Self.logger.info(
"""
Finished reading serverUrl: \(itemServerUrl, privacy: .public)
for user: \(ncAccount.ncKitAccount, privacy: .public)
for user: \(remoteInterface.account.ncKitAccount, privacy: .public)
"""
)

Expand All @@ -170,7 +166,7 @@ extension Enumerator {
Self.logger.warning(
"""
Nil metadatas received in change read at \(itemServerUrl, privacy: .public)
for user: \(ncAccount.ncKitAccount, privacy: .public)
for user: \(remoteInterface.account.ncKitAccount, privacy: .public)
"""
)
}
Expand All @@ -181,7 +177,7 @@ extension Enumerator {
Self.logger.warning(
"""
Nil new metadatas received in change read at \(itemServerUrl, privacy: .public)
for user: \(ncAccount.ncKitAccount, privacy: .public)
for user: \(remoteInterface.account.ncKitAccount, privacy: .public)
"""
)
}
Expand All @@ -192,7 +188,7 @@ extension Enumerator {
Self.logger.warning(
"""
Nil updated metadatas received in change read at \(itemServerUrl, privacy: .public)
for user: \(ncAccount.ncKitAccount, privacy: .public)
for user: \(remoteInterface.account.ncKitAccount, privacy: .public)
"""
)
}
Expand All @@ -203,7 +199,7 @@ extension Enumerator {
Self.logger.warning(
"""
Nil deleted metadatas received in change read at \(itemServerUrl, privacy: .public)
for user: \(ncAccount.ncKitAccount, privacy: .public)
for user: \(remoteInterface.account.ncKitAccount, privacy: .public)
"""
)
}
Expand Down Expand Up @@ -246,7 +242,6 @@ extension Enumerator {
)
let childScanResult = await scanRecursively(
childDirectory,
ncAccount: ncAccount,
remoteInterface: remoteInterface,
dbManager: dbManager,
scanChangesOnly: scanChangesOnly
Expand Down Expand Up @@ -323,7 +318,6 @@ extension Enumerator {

static func readServerUrl(
_ serverUrl: String,
ncAccount: Account,
remoteInterface: RemoteInterface,
dbManager: FilesDatabaseManager,
domain: NSFileProviderDomain? = nil,
Expand All @@ -337,12 +331,13 @@ extension Enumerator {
deletedMetadatas: [ItemMetadata]?,
readError: NKError?
) {
let ncAccount = remoteInterface.account
let ncKitAccount = ncAccount.ncKitAccount

Self.logger.debug(
"""
Starting to read serverUrl: \(serverUrl, privacy: .public)
for user: \(ncAccount.ncKitAccount, privacy: .public)
for user: \(ncKitAccount, privacy: .public)
at depth \(depth.rawValue, privacy: .public).
username: \(ncAccount.username, privacy: .public),
password is empty: \(ncAccount.password == "" ? "EMPTY" : "NOT EMPTY"),
Expand Down
89 changes: 64 additions & 25 deletions Sources/NextcloudFileProviderKit/Enumeration/Enumerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
private let anchor = NSFileProviderSyncAnchor(Date().description.data(using: .utf8)!)
private static let maxItemsPerFileProviderPage = 100
static let logger = Logger(subsystem: Logger.subsystem, category: "enumerator")
let ncAccount: Account
let remoteInterface: RemoteInterface
let ncKitAccount: String
let fastEnumeration: Bool
var serverUrl: String = ""
var isInvalidated = false
Expand All @@ -42,16 +42,15 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {

public init(
enumeratedItemIdentifier: NSFileProviderItemIdentifier,
ncAccount: Account,
remoteInterface: RemoteInterface,
dbManager: FilesDatabaseManager = .shared,
domain: NSFileProviderDomain? = nil,
fastEnumeration: Bool = true,
listener: EnumerationListener? = nil
) {
self.enumeratedItemIdentifier = enumeratedItemIdentifier
self.ncAccount = ncAccount
self.remoteInterface = remoteInterface
self.ncKitAccount = remoteInterface.account.ncKitAccount
self.dbManager = dbManager
self.domain = domain
self.fastEnumeration = fastEnumeration
Expand All @@ -61,7 +60,7 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
Self.logger.debug(
"Providing enumerator for a system defined container: \(enumeratedItemIdentifier.rawValue, privacy: .public)"
)
serverUrl = ncAccount.davFilesUrl
serverUrl = remoteInterface.account.davFilesUrl
} else {
Self.logger.debug(
"Providing enumerator for item with identifier: \(enumeratedItemIdentifier.rawValue, privacy: .public)"
Expand All @@ -80,7 +79,10 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
}

Self.logger.info(
"Set up enumerator for user: \(self.ncAccount.ncKitAccount, privacy: .public) with serverUrl: \(self.serverUrl, privacy: .public)"
"""
Set up enumerator for user: \(self.ncKitAccount, privacy: .public)
with serverUrl: \(self.serverUrl, privacy: .public)
"""
)
super.init()
}
Expand All @@ -101,7 +103,11 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
listener?.enumerationActionStarted(actionId: actionId)

Self.logger.debug(
"Received enumerate items request for enumerator with user: \(self.ncAccount.ncKitAccount, privacy: .public) with serverUrl: \(self.serverUrl, privacy: .public)"
"""
Received enumerate items request for enumerator with user:
\(self.ncKitAccount, privacy: .public)
with serverUrl: \(self.serverUrl, privacy: .public)
"""
)
/*
- inspect the page to determine whether this is an initial or a follow-up request (TODO)
Expand All @@ -118,7 +124,10 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {

if enumeratedItemIdentifier == .trashContainer {
Self.logger.debug(
"Enumerating trash set for user: \(self.ncAccount.ncKitAccount, privacy: .public) with serverUrl: \(self.serverUrl, privacy: .public)"
"""
Enumerating trash set for user: \(self.ncKitAccount, privacy: .public)
with serverUrl: \(self.serverUrl, privacy: .public)
"""
)
// TODO!

Expand Down Expand Up @@ -148,20 +157,26 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
|| page == NSFileProviderPage.initialPageSortedByName as NSFileProviderPage
{
Self.logger.debug(
"Enumerating initial page for user: \(self.ncAccount.ncKitAccount, privacy: .public) with serverUrl: \(self.serverUrl, privacy: .public)"
"""
Enumerating initial page for user: \(self.ncKitAccount, privacy: .public)
with serverUrl: \(self.serverUrl, privacy: .public)
"""
)

Task {
let (metadatas, _, _, _, readError) = await Self.readServerUrl(
serverUrl,
ncAccount: ncAccount,
serverUrl,
remoteInterface: remoteInterface,
dbManager: dbManager
)

guard readError == nil else {
Self.logger.error(
"Finishing enumeration for user: \(self.ncAccount.ncKitAccount, privacy: .public) with serverUrl: \(self.serverUrl, privacy: .public) with error \(readError!.errorDescription, privacy: .public)"
"""
"Finishing enumeration for user: \(self.ncKitAccount, privacy: .public)
with serverUrl: \(self.serverUrl, privacy: .public)
with error \(readError!.errorDescription, privacy: .public)
"""
)

// TODO: Refactor for conciseness
Expand All @@ -174,7 +189,11 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {

guard let metadatas else {
Self.logger.error(
"Finishing enumeration for user: \(self.ncAccount.ncKitAccount, privacy: .public) with serverUrl: \(self.serverUrl, privacy: .public) with invalid metadatas."
"""
Finishing enumeration for user: \(self.ncKitAccount, privacy: .public)
with serverUrl: \(self.serverUrl, privacy: .public)
with invalid metadatas.
"""
)
listener?.enumerationActionFailed(
actionId: actionId, error: NSFileProviderError(.cannotSynchronize)
Expand All @@ -184,7 +203,11 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
}

Self.logger.info(
"Finished reading serverUrl: \(self.serverUrl, privacy: .public) for user: \(self.ncAccount.ncKitAccount, privacy: .public). Processed \(metadatas.count) metadatas"
"""
Finished reading serverUrl: \(self.serverUrl, privacy: .public)
for user: \(self.ncKitAccount, privacy: .public).
Processed \(metadatas.count) metadatas
"""
)

Self.completeEnumerationObserver(
Expand All @@ -202,7 +225,11 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {

let numPage = Int(String(data: page.rawValue, encoding: .utf8)!)!
Self.logger.debug(
"Enumerating page \(numPage, privacy: .public) for user: \(self.ncAccount.ncKitAccount, privacy: .public) with serverUrl: \(self.serverUrl, privacy: .public)"
"""
Enumerating page \(numPage, privacy: .public)
for user: \(self.ncKitAccount, privacy: .public)
with serverUrl: \(self.serverUrl, privacy: .public)
"""
)
// TODO: Handle paging properly
// Self.completeObserver(observer, ncKit: ncKit, numPage: numPage, itemMetadatas: nil)
Expand All @@ -217,7 +244,11 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
listener?.enumerationActionStarted(actionId: actionId)

Self.logger.debug(
"Received enumerate changes request for enumerator for user: \(self.ncAccount.ncKitAccount, privacy: .public) with serverUrl: \(self.serverUrl, privacy: .public)"
"""
Received enumerate changes request for enumerator for user:
\(self.ncKitAccount, privacy: .public)
with serverUrl: \(self.serverUrl, privacy: .public)
"""
)
/*
- query the server for updates since the passed-in sync anchor (TODO)
Expand All @@ -231,7 +262,7 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {

if enumeratedItemIdentifier == .workingSet {
Self.logger.debug(
"Enumerating changes in working set for user: \(self.ncAccount.ncKitAccount, privacy: .public)"
"Enumerating changes in working set for: \(self.ncKitAccount, privacy: .public)"
)

// Unlike when enumerating items we can't progressively enumerate items as we need to wait to resolve which items are truly deleted and which
Expand All @@ -240,7 +271,6 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
let (
_, newMetadatas, updatedMetadatas, deletedMetadatas, error
) = await fullRecursiveScan(
ncAccount: ncAccount,
remoteInterface: remoteInterface,
dbManager: dbManager,
scanChangesOnly: true
Expand All @@ -250,7 +280,7 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
Self.logger.info(
"""
Enumerator invalidated during working set change scan.
For user: \(self.ncAccount.ncKitAccount, privacy: .public)
For user: \(self.ncKitAccount, privacy: .public)
"""
)
listener?.enumerationActionFailed(actionId: actionId, error: NSFileProviderError(.cannotSynchronize))
Expand All @@ -262,7 +292,7 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
Self.logger.info(
"""
Finished recursive change enumeration of working set for user:
\(self.ncAccount.ncKitAccount, privacy: .public)
\(self.ncKitAccount, privacy: .public)
with error: \(error!.errorDescription, privacy: .public)
"""
)
Expand All @@ -277,7 +307,7 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
Self.logger.info(
"""
Finished recursive change enumeration of working set for user:
\(self.ncAccount.ncKitAccount, privacy: .public). Enumerating items.
\(self.ncKitAccount, privacy: .public). Enumerating items.
"""
)

Expand All @@ -295,7 +325,7 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
return
} else if enumeratedItemIdentifier == .trashContainer {
Self.logger.debug(
"Enumerating changes in trash set for user: \(self.ncAccount.ncKitAccount, privacy: .public)"
"Enumerating changes in trash set for user: \(self.ncKitAccount, privacy: .public)"
)
// TODO!

Expand All @@ -305,7 +335,10 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
}

Self.logger.info(
"Enumerating changes for user: \(self.ncAccount.ncKitAccount, privacy: .public) with serverUrl: \(self.serverUrl, privacy: .public)"
"""
Enumerating changes for user: \(self.ncKitAccount, privacy: .public)
with serverUrl: \(self.serverUrl, privacy: .public)
"""
)

// No matter what happens here we finish enumeration in some way, either from the error
Expand All @@ -316,7 +349,6 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
_, newMetadatas, updatedMetadatas, deletedMetadatas, readError
) = await Self.readServerUrl(
serverUrl,
ncAccount: ncAccount,
remoteInterface: remoteInterface,
dbManager: dbManager,
stopAtMatchingEtags: true
Expand All @@ -330,7 +362,11 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {

guard readError == nil else {
Self.logger.error(
"Finishing enumeration of changes for user: \(self.ncAccount.ncKitAccount, privacy: .public) with serverUrl: \(self.serverUrl, privacy: .public) with error: \(readError!.errorDescription, privacy: .public)"
"""
Finishing enumeration of changes for: \(self.ncKitAccount, privacy: .public)
with serverUrl: \(self.serverUrl, privacy: .public)
with error: \(readError!.errorDescription, privacy: .public)
"""
)

let error = readError!.fileProviderError ?? NSFileProviderError(.cannotSynchronize)
Expand Down Expand Up @@ -390,7 +426,10 @@ public class Enumerator: NSObject, NSFileProviderEnumerator {
}

Self.logger.info(
"Finished reading serverUrl: \(self.serverUrl, privacy: .public) for user: \(self.ncAccount.ncKitAccount, privacy: .public)"
"""
Finished reading serverUrl: \(self.serverUrl, privacy: .public)
for user: \(self.ncKitAccount, privacy: .public)
"""
)

Self.completeChangesObserver(
Expand Down
Loading

0 comments on commit 9890a78

Please sign in to comment.