@@ -44,12 +44,16 @@ public extension Item {
4444 Self . logger. error (
4545 """
4646 Could not move file or folder: \( oldRemotePath, privacy: . public)
47- to \( newRemotePath, privacy: . public) ,
48- received error: \( moveError. errorCode, privacy: . public)
49- \( moveError. errorDescription, privacy: . public)
47+ to \( newRemotePath, privacy: . public) ,
48+ received error: \( moveError. errorCode, privacy: . public)
49+ \( moveError. errorDescription, privacy: . public)
5050 """
5151 )
52- return ( nil , moveError. fileProviderError)
52+ return ( nil , moveError. fileProviderError (
53+ handlingCollisionAgainstItemInRemotePath: newRemotePath,
54+ dbManager: dbManager,
55+ remoteInterface: remoteInterface
56+ ) )
5357 }
5458
5559 if isFolder {
@@ -173,7 +177,13 @@ public extension Item {
173177 metadata. status = Status . uploadError. rawValue
174178 metadata. sessionError = error. errorDescription
175179 dbManager. addItemMetadata ( metadata)
176- return ( nil , error. fileProviderError)
180+ // Moving should be done before uploading and should catch collisions already, but,
181+ // it is painless to check here too just in case
182+ return ( nil , error. fileProviderError (
183+ handlingCollisionAgainstItemInRemotePath: remotePath,
184+ dbManager: dbManager,
185+ remoteInterface: remoteInterface
186+ ) )
177187 }
178188
179189 Self . logger. info (
@@ -246,11 +256,7 @@ public extension Item {
246256 )
247257
248258 func remoteErrorToThrow( _ error: NKError ) -> Error {
249- if let error = error. fileProviderError {
250- return error
251- } else {
252- return NSFileProviderError ( . cannotSynchronize)
253- }
259+ return error. fileProviderError ?? NSFileProviderError ( . cannotSynchronize)
254260 }
255261
256262 // 1. Scan the remote contents of the bundle (recursively)
@@ -287,9 +293,9 @@ public extension Item {
287293 Self . logger. error (
288294 """
289295 Could not read server url for item with ocID
290- \( self . itemIdentifier. rawValue, privacy: . public)
291- ( \( self . filename, privacy: . public) ),
292- received nil metadatas
296+ \( self . itemIdentifier. rawValue, privacy: . public)
297+ ( \( self . filename, privacy: . public) ),
298+ received nil metadatas
293299 """
294300 )
295301 throw NSFileProviderError ( . serverUnreachable)
@@ -484,7 +490,7 @@ public extension Item {
484490 Self . logger. error (
485491 """
486492 Could not read new bpi folder at: \( remotePath, privacy: . public) ,
487- received error: \( readError. errorDescription, privacy: . public)
493+ received error: \( readError. errorDescription, privacy: . public)
488494 """
489495 )
490496 throw remoteErrorToThrow ( readError)
@@ -514,6 +520,7 @@ public extension Item {
514520 )
515521 }
516522
523+ // Note: When handling trashing, the server handles filename conflicts for us
517524 private static func trash(
518525 _ modifiedItem: Item ,
519526 account: Account ,
@@ -571,7 +578,7 @@ public extension Item {
571578 Self . logger. error (
572579 """
573580 Received bad error from post-trashing remote scan:
574- \( error. errorDescription, privacy: . public) \( files, privacy: . public)
581+ \( error. errorDescription, privacy: . public) \( files, privacy: . public)
575582 """
576583 )
577584 return ( dirtyItem, error. fileProviderError)
@@ -667,6 +674,7 @@ public extension Item {
667674 return ( postDeleteItem, nil )
668675 }
669676
677+ // Note: When restoring from the trash, the server handles filename conflicts for us
670678 private static func restoreFromTrash(
671679 _ modifiedItem: Item ,
672680 account: Account ,
@@ -711,7 +719,7 @@ public extension Item {
711719 Self . logger. error (
712720 """
713721 Could not restore item \( modifiedItem. filename, privacy: . public) from trash
714- Received error: \( restoreError. errorDescription, privacy: . public)
722+ Received error: \( restoreError. errorDescription, privacy: . public)
715723 """
716724 )
717725 return ( modifiedItem, restoreError. fileProviderError)
0 commit comments