From 53d96a3e97a9757f5a0a2bf356a937533b468980 Mon Sep 17 00:00:00 2001 From: joshua-journey-apps Date: Thu, 10 Jul 2025 11:25:47 +0200 Subject: [PATCH 1/2] fix attachments not being loaded in dev enviornment Refer to this discussion: https://discord.com/channels/1138230179878154300/1387703779662631004 --- Sources/PowerSync/attachments/AttachmentQueue.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/PowerSync/attachments/AttachmentQueue.swift b/Sources/PowerSync/attachments/AttachmentQueue.swift index b7aeee2..317b3cb 100644 --- a/Sources/PowerSync/attachments/AttachmentQueue.swift +++ b/Sources/PowerSync/attachments/AttachmentQueue.swift @@ -413,6 +413,11 @@ open class AttachmentQueue { for attachment in attachments { guard let localUri = attachment.localUri else { + // Redownload synced attachments with missing localUri. + // Can happen when the app is reinstalled and a new sandbox is created in the iOS simulator. + if attachment.state == AttachmentState.synced { + updates.append(attachment.with(state: .queuedDownload)) + } continue } From 40a93b0325cefe262e13f69b7c2618988306403a Mon Sep 17 00:00:00 2001 From: joshua-journey-apps Date: Fri, 11 Jul 2025 10:44:05 +0200 Subject: [PATCH 2/2] redownload attachments with non-existent paths --- .../attachments/AttachmentQueue.swift | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Sources/PowerSync/attachments/AttachmentQueue.swift b/Sources/PowerSync/attachments/AttachmentQueue.swift index 317b3cb..857d998 100644 --- a/Sources/PowerSync/attachments/AttachmentQueue.swift +++ b/Sources/PowerSync/attachments/AttachmentQueue.swift @@ -413,24 +413,26 @@ open class AttachmentQueue { for attachment in attachments { guard let localUri = attachment.localUri else { - // Redownload synced attachments with missing localUri. - // Can happen when the app is reinstalled and a new sandbox is created in the iOS simulator. - if attachment.state == AttachmentState.synced { - updates.append(attachment.with(state: .queuedDownload)) - } continue } let exists = try await localStorage.fileExists(filePath: localUri) - if attachment.state == AttachmentState.synced || - attachment.state == AttachmentState.queuedUpload && - !exists - { - // The file must have been removed from the local storage + if exists { + // The file exists, this is correct + continue + } + + if attachment.state == AttachmentState.queuedUpload { + // The file must have been removed from the local storage before upload was completed updates.append(attachment.with( state: .archived, localUri: .some(nil) // Clears the value )) + } else if attachment.state == AttachmentState.synced { + // The file was downloaded, but removed - trigger redownload + updates.append(attachment.with( + state: .queuedDownload + )) } }