Skip to content

Commit 00ed151

Browse files
committed
refactor: clean up per good-code review
- Remove internal helpers from Postgres.hs export list (withDB, withDB', handleDuplicate, assertUpdated, withLog are not imported externally) - Replace local isNothing_ with Data.Maybe.isNothing in Env.hs - Consolidate duplicate/unused imports in XFTPStoreTests.hs - Add file_path IS NULL and status guards to STM setFilePath, matching the Postgres implementation semantics
1 parent 5de4f78 commit 00ed151

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

src/Simplex/FileTransfer/Server/Env.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import Simplex.FileTransfer.Server.Store
4141
import Simplex.Messaging.Agent.Store.Shared (MigrationConfirmation)
4242
#if defined(dbServerPostgres)
4343
import Data.Functor (($>))
44+
import Data.Maybe (isNothing)
4445
import Simplex.FileTransfer.Server.Store.Postgres (PostgresFileStore, importFileStore, exportFileStore)
4546
import Simplex.FileTransfer.Server.Store.Postgres.Config (PostgresFileStoreCfg (..), defaultXFTPDBOpts)
4647
import Simplex.Messaging.Server.CLI (iniDBOptions, settingIsOn)
@@ -190,14 +191,11 @@ checkFileStoreMode ini storeType storeLogFilePath = case storeType of
190191
"database" -> do
191192
storeLogExists <- doesFileExist storeLogFilePath
192193
let dbStoreLogOn = settingIsOn "STORE_LOG" "db_store_log" ini
193-
when (storeLogExists && isNothing_ dbStoreLogOn) $ do
194+
when (storeLogExists && isNothing dbStoreLogOn) $ do
194195
putStrLn $ "Error: store log file " <> storeLogFilePath <> " exists but store_files is `database`."
195196
putStrLn "Use `file-server database import` to migrate, or set `db_store_log: on`."
196197
exitFailure
197198
_ -> pure ()
198-
where
199-
isNothing_ Nothing = True
200-
isNothing_ _ = False
201199
#else
202200
checkFileStoreMode _ _ _ = pure ()
203201
#endif

src/Simplex/FileTransfer/Server/Store.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,15 @@ instance FileStoreClass STMFileStore where
9797
pure $ Right ()
9898

9999
setFilePath st sId fPath = atomically $
100-
withSTMFile st sId $ \FileRec {filePath} -> do
101-
writeTVar filePath (Just fPath)
102-
pure $ Right ()
100+
withSTMFile st sId $ \FileRec {filePath, fileStatus} -> do
101+
readTVar filePath >>= \case
102+
Just _ -> pure $ Left AUTH
103+
Nothing ->
104+
readTVar fileStatus >>= \case
105+
EntityActive -> do
106+
writeTVar filePath (Just fPath)
107+
pure $ Right ()
108+
_ -> pure $ Left AUTH
103109

104110
addRecipient st@STMFileStore {recipients} senderId (FileRecipient rId rKey) = atomically $
105111
withSTMFile st senderId $ \FileRec {recipientIds} -> do

src/Simplex/FileTransfer/Server/Store/Postgres.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99

1010
module Simplex.FileTransfer.Server.Store.Postgres
1111
( PostgresFileStore (..),
12-
withDB,
13-
withDB',
14-
handleDuplicate,
15-
assertUpdated,
16-
withLog,
1712
importFileStore,
1813
exportFileStore,
1914
)

tests/CoreTests/XFTPStoreTests.hs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,17 @@
66
module CoreTests.XFTPStoreTests (xftpStoreTests, xftpMigrationTests) where
77

88
import Control.Monad
9-
import qualified Data.ByteString.Char8 as B
109
import Data.Word (Word32)
11-
import qualified Data.Set as S
1210
import Simplex.FileTransfer.Protocol (FileInfo (..), SFileParty (..))
1311
import Simplex.FileTransfer.Server.Store
14-
import Simplex.FileTransfer.Server.Store.Postgres (PostgresFileStore)
15-
import Simplex.FileTransfer.Server.Store.Postgres.Config (PostgresFileStoreCfg)
16-
import Simplex.FileTransfer.Server.StoreLog
12+
import Simplex.FileTransfer.Server.Store.Postgres (PostgresFileStore, importFileStore, exportFileStore)
13+
import Simplex.FileTransfer.Server.StoreLog (closeStoreLog, readWriteFileStore, writeFileStore)
1714
import Simplex.FileTransfer.Transport (XFTPErrorType (..))
1815
import qualified Simplex.Messaging.Crypto as C
1916
import Simplex.Messaging.Protocol (BlockingInfo (..), BlockingReason (..), EntityId (..))
2017
import Simplex.Messaging.Server.QueueStore (ServerEntityStatus (..))
21-
import Simplex.Messaging.SystemTime (RoundedSystemTime (..))
22-
import Simplex.FileTransfer.Server.Store.Postgres (importFileStore, exportFileStore)
23-
import Simplex.FileTransfer.Server.StoreLog (readWriteFileStore, writeFileStore)
2418
import Simplex.Messaging.Server.StoreLog (openWriteStoreLog)
19+
import Simplex.Messaging.SystemTime (RoundedSystemTime (..))
2520
import System.Directory (doesFileExist, removeFile)
2621
import Test.Hspec hiding (fit, it)
2722
import UnliftIO.STM

0 commit comments

Comments
 (0)