Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
109370b
Add materialisation-relevant property to item metadatas for folders
claucambra Jun 13, 2025
30f849a
Add method to retrieve all materialised items from database
claucambra Jun 13, 2025
2023a23
Add method to test retrieval of all materialised files from database
claucambra Jun 13, 2025
3cd9b6c
Observe both newly unmaterialised and newly materialised items
claucambra Jun 13, 2025
1eef898
Fix visitedDirectory state in conversions to RealmItemMetadata
claucambra Jun 13, 2025
4af5e9e
Check corrected state in FilesDatabaseManager
claucambra Jun 13, 2025
0c2b5c5
Add logging to MaterialisedEnumerationObserver
claucambra Jun 13, 2025
1399ff9
Improve tests for MaterialisedEnumerationObserver
claucambra Jun 13, 2025
f00b988
Log visitedDirectory state
claucambra Jun 13, 2025
4ce0b0d
Modify readServerUrl to mark directories as visited where relevant AN…
claucambra Jun 13, 2025
6220410
Amend Item fetch behaviour to account for new readServerUrl behaviour
claucambra Jun 13, 2025
996d8f0
Amend Item pakcage/bundle modify to account for new readServerUrl beh…
claucambra Jun 13, 2025
46549ce
Modify database manager handling of depth 1 read and account for read…
claucambra Jun 13, 2025
6ad99ab
Make MockRemoteItem versionIdentifier modifiable
claucambra Jun 13, 2025
d7a98c7
Return 404 when enumerating non-existent item URL in MockRemoteInterface
claucambra Jun 13, 2025
37cdea9
Modify working set enumeration to only return materialised items
claucambra Jun 13, 2025
9d71867
Modify change enumeration for working set to only check for materiali…
claucambra Jun 13, 2025
10e9a4f
Remove unused recursive scan components from sync engine
claucambra Jun 13, 2025
83fd374
Remove unused components of EnumeratorPageResponse
claucambra Jun 13, 2025
f149ab2
Address readServerUrl related changes in enumerator tests
claucambra Jun 13, 2025
50350b9
Avoid scanning materialised children of materialised parents we have …
claucambra Jun 13, 2025
051bb9a
Imitate NextcloudKit behaviour in MockRemoteItem conversion to NKFile
claucambra Jun 16, 2025
65f0b63
Try to clean up received path a bit in MockRemoteInterface
claucambra Jun 16, 2025
5f2d1cd
Prevent bad trimming of serverUrl for root item in MockRemoteItem con…
claucambra Jun 16, 2025
d4cf03f
Fix up mangling of root container metadata performed by NextcloudKit
claucambra Jun 16, 2025
77a2e17
Ingest metadata for the root container
claucambra Jun 16, 2025
91703b1
Do not create fake root metadata for working set enumeration
claucambra Jun 16, 2025
a0b83bd
Exclude root container from child metadata change calculation
claucambra Jun 16, 2025
8c0e0b5
Fix sorting of filenames
claucambra Jun 16, 2025
8f9c974
Improve deleted metadata log formatting
claucambra Jun 16, 2025
10d04ab
Mark moved metadatas as updated and not deleted in working set change…
claucambra Jun 16, 2025
97235f9
Explain optimisation with examined urls
claucambra Jun 16, 2025
1c6ae15
Also catch non-bungled root metadata metadatas
claucambra Jun 16, 2025
5d206aa
Make sure to check for root container metadata after changing target …
claucambra Jun 16, 2025
2ad7290
Make chunkedConcurrentMap compatible with all random access collections
claucambra Jun 16, 2025
355a625
Ensure we do not repeat the target metadata in the child metadatas du…
claucambra Jun 16, 2025
aca2c44
Add tests for nkfile conversions
claucambra Jun 16, 2025
d661817
Move root correction to nkfile conversion
claucambra Jun 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ public final class FilesDatabaseManager: Sendable {
deletedMetadatas.append(metadataToDelete)

Self.logger.debug(
"Deleting item metadata during update. ocID: \(existingMetadata.ocId, privacy: .public), etag: \(existingMetadata.etag, privacy: .public), fileName: \(existingMetadata.fileName, privacy: .public)"
"""
Deleting item metadata during update.
ocID: \(existingMetadata.ocId, privacy: .public)
etag: \(existingMetadata.etag, privacy: .public)
fileName: \(existingMetadata.fileName, privacy: .public)"
"""
)
}

Expand Down Expand Up @@ -336,24 +341,48 @@ public final class FilesDatabaseManager: Sendable {
//
// - the ones that do exist remotely still are either the same or have been updated
// - the ones that don't have been deleted
var cleanServerUrl = serverUrl
if cleanServerUrl.last == "/" {
cleanServerUrl.removeLast()
}
let existingMetadatas = database
.objects(RealmItemMetadata.self)
.where { $0.account == account && $0.serverUrl == serverUrl && $0.uploaded }
.where {
// Don't worry — root will be updated at the end of this method if is the target
$0.ocId != NSFileProviderItemIdentifier.rootContainer.rawValue &&
$0.account == account &&
$0.serverUrl == cleanServerUrl &&
$0.uploaded
}

var updatedChildMetadatas = updatedMetadatas

let readTargetMetadata: SendableItemMetadata?
if let targetMetadata = updatedMetadatas.first {
if targetMetadata.directory {
readTargetMetadata = updatedChildMetadatas.removeFirst()
} else {
readTargetMetadata = targetMetadata
}
} else {
readTargetMetadata = nil
}

// NOTE: These metadatas are managed -- be careful!
let metadatasToDelete = processItemMetadatasToDelete(
existingMetadatas: existingMetadatas,
updatedMetadatas: updatedMetadatas)
updatedMetadatas: updatedChildMetadatas
)
let metadatasToDeleteCopy = metadatasToDelete.map { SendableItemMetadata(value: $0) }

let metadatasToChange = processItemMetadatasToUpdate(
existingMetadatas: existingMetadatas,
updatedMetadatas: updatedMetadatas,
updatedMetadatas: updatedChildMetadatas,
keepExistingDownloadState: keepExistingDownloadState
)

var metadatasToUpdate = metadatasToChange.updatedMetadatas
let metadatasToCreate = metadatasToChange.newMetadatas
var metadatasToCreate = metadatasToChange.newMetadatas
let directoriesNeedingRename = metadatasToChange.directoriesNeedingRename

for metadata in directoriesNeedingRename {
Expand All @@ -366,6 +395,26 @@ public final class FilesDatabaseManager: Sendable {
}
}

if var readTargetMetadata {
if let existing = itemMetadata(ocId: readTargetMetadata.ocId) {
if existing.status == Status.normal.rawValue,
!existing.isInSameDatabaseStoreableRemoteState(readTargetMetadata)
{
Self.logger.info("Depth 1 read target changed: \(readTargetMetadata.ocId)")
if keepExistingDownloadState {
readTargetMetadata.downloaded = existing.downloaded
}
if readTargetMetadata.directory {
readTargetMetadata.visitedDirectory = true
}
metadatasToUpdate.insert(readTargetMetadata, at: 0)
}
} else {
Self.logger.info("Depth 1 read target is new: \(readTargetMetadata.ocId)")
metadatasToCreate.insert(readTargetMetadata, at: 0)
}
}

try database.write {
database.delete(metadatasToDelete)
database.add(metadatasToUpdate.map { RealmItemMetadata(value: $0) }, update: .modified)
Expand Down Expand Up @@ -463,6 +512,7 @@ public final class FilesDatabaseManager: Sendable {
trashbinFileName: \(metadata.trashbinFileName, privacy: .public)
downloaded: \(metadata.downloaded, privacy: .public)
uploaded: \(metadata.uploaded, privacy: .public)
visitedDirectory: \(metadata.visitedDirectory, privacy: .public)
"""
)
}
Expand Down Expand Up @@ -601,4 +651,13 @@ public final class FilesDatabaseManager: Sendable {
}
return NSFileProviderItemIdentifier(parentMetadata.ocId)
}

public func materialisedItemMetadatas(account: String) -> [SendableItemMetadata] {
itemMetadatas
.where {
$0.account == account &&
(($0.directory && $0.visitedDirectory) || (!$0.directory && $0.downloaded))
}
.toUnmanagedResults()
}
}
Loading