From 6183501285dcd07154b1f8e079609c5991025210 Mon Sep 17 00:00:00 2001 From: jack Date: Thu, 25 Sep 2025 01:15:29 +0200 Subject: [PATCH] Copy imported files before sending to preserve access --- bitchat/Views/ContentView.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bitchat/Views/ContentView.swift b/bitchat/Views/ContentView.swift index 919d86fc..97ddddc1 100644 --- a/bitchat/Views/ContentView.swift +++ b/bitchat/Views/ContentView.swift @@ -2055,8 +2055,20 @@ private extension ContentView { } func handleImportedFile(url: URL) async { - await MainActor.run { - viewModel.sendFileAttachment(from: url) + do { + let fileManager = FileManager.default + let tempDir = fileManager.temporaryDirectory + let fileName = url.lastPathComponent.isEmpty ? "attachment" : url.lastPathComponent + let destination = tempDir.appendingPathComponent(UUID().uuidString + "_" + fileName) + if fileManager.fileExists(atPath: destination.path) { + try fileManager.removeItem(at: destination) + } + try fileManager.copyItem(at: url, to: destination) + await MainActor.run { + viewModel.sendFileAttachment(from: destination) + } + } catch { + SecureLogger.error("File copy failed before send: \(error)", category: .session) } }