Skip to content
Merged
Changes from all commits
Commits
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
20 changes: 19 additions & 1 deletion Sources/PowerSync/attachments/AttachmentQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ public actor AttachmentQueue: AttachmentQueueProtocol {
errorHandler: self.errorHandler,
syncThrottle: self.syncThrottleDuration
)

Task {
do {
try await attachmentsService.withContext { context in
try await self.verifyAttachments(context: context)
}
} catch {
self.logger.error("Error verifying attachments: \(error.localizedDescription)", tag: logTag)
}
}
}

public func getLocalUri(_ filename: String) async -> String {
Expand Down Expand Up @@ -463,7 +473,15 @@ public actor AttachmentQueue: AttachmentQueueProtocol {
continue
}

if attachment.state == AttachmentState.queuedUpload {
let newLocalUri = await getLocalUri(attachment.filename)
let newExists = try await localStorage.fileExists(filePath: newLocalUri)
if newExists {
// The file exists but the localUri is broken, lets update it.
// E.g. this happens in simulators that change the path to the app's sandbox.
updates.append(attachment.with(
localUri: newLocalUri
))
} else if attachment.state == AttachmentState.queuedUpload || attachment.state == AttachmentState.archived {
// The file must have been removed from the local storage before upload was completed
updates.append(attachment.with(
state: .archived,
Expand Down