From 3835ae3876f071958a7e059110b2b58e20629162 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Mon, 16 Dec 2019 19:36:02 +0100 Subject: [PATCH] actually create one MVar per DB context ... --- lib/core/src/Cardano/Wallet/DB/Sqlite.hs | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/core/src/Cardano/Wallet/DB/Sqlite.hs b/lib/core/src/Cardano/Wallet/DB/Sqlite.hs index 6fc72584a8c..e33efb9c3d7 100644 --- a/lib/core/src/Cardano/Wallet/DB/Sqlite.hs +++ b/lib/core/src/Cardano/Wallet/DB/Sqlite.hs @@ -220,7 +220,6 @@ newDBFactory -- ^ Path to database directory, or Nothing for in-memory database -> IO (DBFactory IO s k) newDBFactory cfg tr mDatabaseDir = do - mvar <- newEmptyMVar case mDatabaseDir of Nothing -> pure DBFactory { withDatabase = \_ action -> @@ -228,20 +227,23 @@ newDBFactory cfg tr mDatabaseDir = do , removeDatabase = \_ -> pure () } - Just databaseDir -> pure DBFactory - { withDatabase = \wid action -> - withDBLayer cfg tracerDB (Just $ databaseFile wid) $ \(ctx,db) -> do - putMVar mvar ctx - action db - , removeDatabase = \wid -> do - let files = - [ databaseFile wid - , databaseFile wid <> "-wal" - , databaseFile wid <> "-shm" - ] - readMVar mvar >>= destroyDBLayer - mapM_ removePathForcibly files - } + Just databaseDir -> do + mvar <- newEmptyMVar + pure DBFactory + { withDatabase = \wid action -> + withDBLayer cfg tracerDB (Just $ databaseFile wid) + $ \(ctx,db) -> do + putMVar mvar ctx + action db + , removeDatabase = \wid -> do + let files = + [ databaseFile wid + , databaseFile wid <> "-wal" + , databaseFile wid <> "-shm" + ] + readMVar mvar >>= destroyDBLayer + mapM_ removePathForcibly files + } where databaseFilePrefix = keyTypeDescriptor $ Proxy @k databaseFile wid =