Skip to content

Commit 6f40348

Browse files
committed
Write cache files atomically
Fixes #1540.
1 parent f18ec5f commit 6f40348

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

dhall/dhall.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ Library
405405
aeson >= 1.0.0.0 && < 1.5 ,
406406
aeson-pretty < 0.9 ,
407407
ansi-terminal >= 0.6.3.1 && < 0.11,
408+
atomic-write >= 0.2.0.6 && < 0.3 ,
408409
bytestring < 0.11,
409410
case-insensitive < 1.3 ,
410411
cborg >= 0.2.0.0 && < 0.3 ,

dhall/src/Dhall/Import.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ import qualified Dhall.Map
200200
import qualified Dhall.Parser
201201
import qualified Dhall.Pretty.Internal
202202
import qualified Dhall.TypeCheck
203+
import qualified System.AtomicWrite.Writer.ByteString
203204
import qualified System.Environment
204205
import qualified System.Info
205206
import qualified System.IO
@@ -554,7 +555,7 @@ writeToSemanticCache :: Dhall.Crypto.SHA256Digest -> Data.ByteString.ByteString
554555
writeToSemanticCache hash bytes = do
555556
_ <- Maybe.runMaybeT $ do
556557
cacheFile <- getCacheFile "dhall" hash
557-
liftIO (Data.ByteString.writeFile cacheFile bytes)
558+
liftIO (System.AtomicWrite.Writer.ByteString.atomicWriteFile cacheFile bytes)
558559
return ()
559560

560561
-- Check the "semi-semantic" disk cache, otherwise typecheck and normalise from
@@ -669,7 +670,7 @@ writeToSemisemanticCache :: Dhall.Crypto.SHA256Digest -> Data.ByteString.ByteStr
669670
writeToSemisemanticCache semisemanticHash bytes = do
670671
_ <- Maybe.runMaybeT $ do
671672
cacheFile <- getCacheFile "dhall-haskell" semisemanticHash
672-
liftIO (Data.ByteString.writeFile cacheFile bytes)
673+
liftIO (System.AtomicWrite.Writer.ByteString.atomicWriteFile cacheFile bytes)
673674
return ()
674675

675676
-- Fetch source code directly from disk/network

0 commit comments

Comments
 (0)