From ec268e20066423e2bb4f2bf13499953383dfabc6 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Thu, 24 Aug 2023 19:11:44 +0100 Subject: [PATCH] agent: wait while agent is in foreground to continue xftp operation (#831) --- src/Simplex/FileTransfer/Agent.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Simplex/FileTransfer/Agent.hs b/src/Simplex/FileTransfer/Agent.hs index 7ca1e5a4f..9f629350c 100644 --- a/src/Simplex/FileTransfer/Agent.hs +++ b/src/Simplex/FileTransfer/Agent.hs @@ -204,6 +204,7 @@ runXFTPRcvWorker c srv doWork = do let chunkSpec = XFTPRcvChunkSpec chunkPath (unFileSize chunkSize) (unFileDigest digest) relChunkPath = fileTmpPath takeFileName chunkPath agentXFTPDownloadChunk c userId digest replica chunkSpec + atomically $ waitUntilForeground c (complete, progress) <- withStore c $ \db -> runExceptT $ do liftIO $ updateRcvFileChunkReceived db (rcvChunkReplicaId replica) rcvChunkId relChunkPath RcvFile {size = FileSize total, chunks} <- ExceptT $ getRcvFile db rcvFileId @@ -261,6 +262,7 @@ runXFTPRcvLocalWorker c doWork = do void $ liftError (INTERNAL . show) $ decryptChunks encSize chunkPaths key nonce $ \_ -> pure fsSavePath notify c rcvFileEntityId $ RFDONE fsSavePath forM_ tmpPath (removePath <=< toFSFilePath) + atomically $ waitUntilForeground c withStore' c (`updateRcvFileComplete` rcvFileId) where getChunkPaths :: [RcvFileChunk] -> m [FilePath] @@ -478,6 +480,7 @@ runXFTPSndWorker c srv doWork = do let chunkSpec' = chunkSpec {filePath = fsFilePath} :: XFTPChunkSpec atomically $ assertAgentForeground c agentXFTPUploadChunk c userId chunkDigest replica' chunkSpec' + atomically $ waitUntilForeground c sf@SndFile {sndFileEntityId, prefixPath, chunks} <- withStore c $ \db -> do updateSndChunkReplicaStatus db sndChunkReplicaId SFRSUploaded getSndFile db sndFileId