Skip to content

Commit 40a93b0

Browse files
redownload attachments with non-existent paths
1 parent 53d96a3 commit 40a93b0

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Sources/PowerSync/attachments/AttachmentQueue.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,24 +413,26 @@ open class AttachmentQueue {
413413

414414
for attachment in attachments {
415415
guard let localUri = attachment.localUri else {
416-
// Redownload synced attachments with missing localUri.
417-
// Can happen when the app is reinstalled and a new sandbox is created in the iOS simulator.
418-
if attachment.state == AttachmentState.synced {
419-
updates.append(attachment.with(state: .queuedDownload))
420-
}
421416
continue
422417
}
423418

424419
let exists = try await localStorage.fileExists(filePath: localUri)
425-
if attachment.state == AttachmentState.synced ||
426-
attachment.state == AttachmentState.queuedUpload &&
427-
!exists
428-
{
429-
// The file must have been removed from the local storage
420+
if exists {
421+
// The file exists, this is correct
422+
continue
423+
}
424+
425+
if attachment.state == AttachmentState.queuedUpload {
426+
// The file must have been removed from the local storage before upload was completed
430427
updates.append(attachment.with(
431428
state: .archived,
432429
localUri: .some(nil) // Clears the value
433430
))
431+
} else if attachment.state == AttachmentState.synced {
432+
// The file was downloaded, but removed - trigger redownload
433+
updates.append(attachment.with(
434+
state: .queuedDownload
435+
))
434436
}
435437
}
436438

0 commit comments

Comments
 (0)