Skip to content

Commit

Permalink
dhall format --inplace: Write file atomically
Browse files Browse the repository at this point in the history
Fixes #498.
  • Loading branch information
sjakobi committed Dec 2, 2019
1 parent 85645a2 commit 52ff25c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dhall/src/Dhall/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import qualified Control.Exception
import qualified Data.Text.IO
import qualified Dhall.Pretty
import qualified Dhall.Util
import qualified System.AtomicWrite.Writer.LazyText as AtomicWrite.LazyText
import qualified System.Console.ANSI
import qualified System.IO

Expand Down Expand Up @@ -68,8 +69,9 @@ format (Format {..}) = do

case inplace of
InputFile file -> do
System.IO.withFile file System.IO.WriteMode (\handle -> do
Pretty.Terminal.renderIO handle (Pretty.unAnnotateS docStream))
AtomicWrite.LazyText.atomicWriteFile
file
(Pretty.Text.renderLazy docStream)

StandardInput -> do
supportsANSI <- System.Console.ANSI.hSupportsANSI System.IO.stdout
Expand Down

0 comments on commit 52ff25c

Please sign in to comment.