From 0d28333919fcc0c76feaafec2db27d335502dfed Mon Sep 17 00:00:00 2001 From: shum Date: Thu, 2 Apr 2026 12:42:16 +0000 Subject: [PATCH] fix: handle setFilePath error in receiveServerFile setFilePath result was discarded with void. If it failed (file deleted concurrently, or double-upload where file_path IS NULL guard rejected the second write), the server still reported FROk, incremented stats, and left usedStorage permanently inflated. Now the error is checked: on failure, reserved storage is released and AUTH is returned. --- src/Simplex/FileTransfer/Server.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Simplex/FileTransfer/Server.hs b/src/Simplex/FileTransfer/Server.hs index fd6781acb..125bc4600 100644 --- a/src/Simplex/FileTransfer/Server.hs +++ b/src/Simplex/FileTransfer/Server.hs @@ -560,12 +560,17 @@ processXFTPRequest HTTP2Body {bodyPart} = \case Right () -> do stats <- asks serverStats st <- asks store - withFileLog $ \sl -> logPutFile sl senderId fPath - void $ liftIO $ setFilePath st senderId fPath - incFileStat filesUploaded - incFileStat filesCount - liftIO $ atomicModifyIORef'_ (filesSize stats) (+ fromIntegral size) - pure FROk + liftIO (setFilePath st senderId fPath) >>= \case + Right () -> do + withFileLog $ \sl -> logPutFile sl senderId fPath + incFileStat filesUploaded + incFileStat filesCount + liftIO $ atomicModifyIORef'_ (filesSize stats) (+ fromIntegral size) + pure FROk + Left _e -> do + us <- asks usedStorage + atomically $ modifyTVar' us $ subtract (fromIntegral size) + pure $ FRErr AUTH Left e -> do us <- asks usedStorage atomically $ modifyTVar' us $ subtract (fromIntegral size)