Skip to content

Commit 525aaa2

Browse files
committed
Build collision errors properly in creation step
Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
1 parent ef857a8 commit 525aaa2

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

Sources/NextcloudFileProviderKit/Item/Item+Create.swift

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ public extension Item {
4040
Self.logger.error(
4141
"""
4242
Could not create new folder at: \(remotePath, privacy: .public),
43-
received error: \(createError.errorCode, privacy: .public)
44-
\(createError.errorDescription, privacy: .public)
43+
received error: \(createError.errorCode, privacy: .public)
44+
\(createError.errorDescription, privacy: .public)
4545
"""
4646
)
47-
return (nil, createError.fileProviderError)
47+
return (nil, createError.fileProviderError(
48+
handlingCollisionAgainstItemInRemotePath: remotePath,
49+
dbManager: dbManager,
50+
remoteInterface: remoteInterface
51+
))
4852
}
4953

5054
// Read contents after creation
@@ -71,11 +75,15 @@ public extension Item {
7175
Self.logger.error(
7276
"""
7377
Could not read new folder at: \(remotePath, privacy: .public),
74-
received error: \(readError.errorCode, privacy: .public)
75-
\(readError.errorDescription, privacy: .public)
78+
received error: \(readError.errorCode, privacy: .public)
79+
\(readError.errorDescription, privacy: .public)
7680
"""
7781
)
78-
return (nil, readError.fileProviderError)
82+
return (nil, readError.fileProviderError(
83+
handlingCollisionAgainstItemInRemotePath: remotePath,
84+
dbManager: dbManager,
85+
remoteInterface: remoteInterface
86+
))
7987
}
8088

8189
guard var (directoryMetadata, _, _) = await files.toDirectoryReadMetadatas(account: account)
@@ -138,12 +146,16 @@ public extension Item {
138146
Self.logger.error(
139147
"""
140148
Could not upload item with filename: \(itemTemplate.filename, privacy: .public),
141-
received error: \(error.errorCode, privacy: .public)
142-
\(error.errorDescription, privacy: .public)
143-
received ocId: \(ocId ?? "empty", privacy: .public)
149+
received error: \(error.errorCode, privacy: .public)
150+
\(error.errorDescription, privacy: .public)
151+
received ocId: \(ocId ?? "empty", privacy: .public)
144152
"""
145153
)
146-
return (nil, error.fileProviderError)
154+
return (nil, error.fileProviderError(
155+
handlingCollisionAgainstItemInRemotePath: remotePath,
156+
dbManager: dbManager,
157+
remoteInterface: remoteInterface
158+
))
147159
}
148160

149161
Self.logger.info(
@@ -253,11 +265,7 @@ public extension Item {
253265
}
254266

255267
func remoteErrorToThrow(_ error: NKError) -> Error {
256-
if let error = error.fileProviderError {
257-
return error
258-
} else {
259-
return NSFileProviderError(.cannotSynchronize)
260-
}
268+
return error.fileProviderError ?? NSFileProviderError(.cannotSynchronize)
261269
}
262270

263271
let contentsPath = contents.path
@@ -551,8 +559,8 @@ public extension Item {
551559
Self.logger.debug(
552560
"""
553561
Item: \(newServerUrlFileName, privacy: .public),
554-
is a bundle or package whose root folder already exists, ignoring errors.
555-
Fetching remote information and proceeding with creation of internal contents.
562+
is a bundle or package whose root folder already exists, ignoring errors.
563+
Fetching remote information, proceeding with creation of internal contents.
556564
"""
557565
)
558566
let (metadatas, _, _, _, readError) = await Enumerator.readServerUrl(

Sources/NextcloudFileProviderKit/Item/Item+CreateLockFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ extension Item {
129129
dbManager.addItemMetadata(metadata)
130130

131131
progress.completedUnitCount = 1
132-
var returnError = error.fileProviderError
132+
var returnError = error.fileProviderError // No need to handle problem cases, no upload here
133133
if #available(macOS 13.0, *), error == .success {
134134
returnError = NSFileProviderError(.excludedFromSync)
135135
}

0 commit comments

Comments
 (0)