88import FileProvider
99
1010extension Item {
11+ // Just modifies metadata
1112 func modifyUnuploaded(
1213 itemTarget: NSFileProviderItem ,
1314 baseVersion: NSFileProviderItemVersion = NSFileProviderItemVersion ( ) ,
@@ -20,42 +21,55 @@ extension Item {
2021 forcedChunkSize: Int ? = nil ,
2122 progress: Progress = . init( ) ,
2223 dbManager: FilesDatabaseManager
23- ) async -> ( Item ? , Error ? ) {
24- guard newContents != nil || domain != nil else {
25- Self . logger. error (
26- """
27- Unable to upload modified item that was previously ignored.
28- filename: \( self . filename, privacy: . public)
29- either the domain is nil, the provided contents are nil, or both.
30- """
31- )
32- return ( nil , NSFileProviderError ( . cannotSynchronize) )
24+ ) -> Item ? {
25+ var modifiedParentItemIdentifier = parentItemIdentifier
26+ var modifiedMetadata = metadata
27+
28+ if changedFields. contains ( . filename) {
29+ modifiedMetadata. fileName = itemTarget. filename
30+ if !isLockFileName( modifiedMetadata. fileName) {
31+ modifiedMetadata. classFile = " "
32+ // Do the actual upload at the end, not yet
33+ }
34+ }
35+ if changedFields. contains ( . contents) ,
36+ let newSize = try ? newContents? . resourceValues ( forKeys: [ . fileSizeKey] ) . fileSize
37+ {
38+ modifiedMetadata. size = Int64 ( newSize)
3339 }
34- let modifiedItem = self
35- var contentsLocation = newContents
36- if contentsLocation == nil {
37- assert ( domain != nil )
38- guard let domain, let localUrl = await localUrlForContents ( domain: domain) else {
40+ if changedFields. contains ( . parentItemIdentifier) {
41+ guard let parentMetadata = dbManager. itemMetadata (
42+ ocId: itemTarget. parentItemIdentifier. rawValue
43+ ) else {
3944 Self . logger. error (
4045 """
41- Unable to upload modified item that was previously ignored.
42- filename: \( modifiedItem. filename, privacy: . public)
43- local url for contents could not be acquired.
46+ Unable to find new parent item identifier during unuploaded item modification.
47+ Filename: \( self . filename, privacy: . public)
4448 """
4549 )
46- return ( nil , NSFileProviderError ( . cannotSynchronize ) )
50+ return nil
4751 }
48- contentsLocation = localUrl
52+ modifiedMetadata. serverUrl = parentMetadata. serverUrl + " / " + parentMetadata. fileName
53+ modifiedParentItemIdentifier = . init( parentMetadata. ocId)
4954 }
50- return await Self . create (
51- basedOn: itemTarget,
52- contents: contentsLocation,
53- domain: domain,
55+ if changedFields. contains ( . creationDate) ,
56+ let newCreationDate = itemTarget. creationDate,
57+ let newCreationDate
58+ {
59+ modifiedMetadata. creationDate = newCreationDate
60+ }
61+ if changedFields. contains ( . contentModificationDate) ,
62+ let newModificationDate = itemTarget. contentModificationDate,
63+ let newModificationDate
64+ {
65+ modifiedMetadata. date = newModificationDate
66+ }
67+
68+ return Item (
69+ metadata: modifiedMetadata,
70+ parentItemIdentifier: modifiedParentItemIdentifier,
5471 account: account,
5572 remoteInterface: remoteInterface,
56- ignoredFiles: ignoredFiles,
57- forcedChunkSize: forcedChunkSize,
58- progress: progress,
5973 dbManager: dbManager
6074 )
6175 }
0 commit comments