Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hoogle.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ library
storable-tuple,
tar,
template-haskell,
temporary,
text >= 2,
time >= 1.5,
transformers,
Expand Down
9 changes: 7 additions & 2 deletions src/General/Store.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ import General.Util
import Numeric.Extra
import Paths_hoogle
import Prelude
import System.IO.Extra
import System.Directory (renameFile)
import System.FilePath (takeDirectory, takeFileName)
import System.IO.Extra (Handle, hTell, hClose, hPutBuf)
import System.IO.MMap
import System.IO.Temp (withTempFile)
import System.IO.Unsafe

-- Ensure the string is always 25 chars long, so version numbers don't change its size
Expand Down Expand Up @@ -108,7 +111,7 @@ storeWriteFile :: FilePath -> (StoreWrite -> IO a) -> IO ([String], a)
storeWriteFile file act = do
atoms <- newIORef Map.empty
parts <- newIORef Nothing
withBinaryFile file WriteMode $ \h -> do
withTempFile (takeDirectory file) (takeFileName file) $ \tmpFile h -> do
-- put the version string at the start and end, so we can tell truncation vs wrong version
BS.hPut h verString
ref <- newIORef $ SW h (BS.length verString) []
Expand All @@ -130,6 +133,8 @@ storeWriteFile file act = do
let stats = prettyTable 0 "Bytes" $
("Overheads", intToDouble $ fromIntegral final - sum (map atomSize $ Map.elems atoms)) :
[(name ++ " :: " ++ atomType, intToDouble atomSize) | (name, Atom{..}) <- Map.toList atoms]
hClose h
renameFile tmpFile file
pure (stats, res)

storeWrite :: (Typeable (t a), Typeable a, Stored a) => StoreWrite -> t a -> a -> IO ()
Expand Down