on master help sign in
Provide a workaround for Windows truncation failure (fixes #178)
commit610a817c3a156b6d0244f588de7e57e2bd5f0db6 authorMichael Snoyman <michael@snoyman.com> dateWed 6 Nov 2019, 09:41 (7 years ago) parent14c8107
3 files changed+17
libyaml/ChangeLog.md+4 libyaml/package.yaml+2 libyaml/src/Text/Libyaml.hs+11
libyaml/ChangeLog.md+4
@@ -1,5 +1,9 @@
11# Changelog for libyaml
22
3+## 0.1.1.1
4+
5+* Work around GHC 8.6.5 issue on Windows preventing truncated files. [#178](https://github.com/snoyberg/yaml/issues/178)
6+
37## 0.1.1.0
48
59* Add options to `FormatOptions` to govern when tags rendered explicitly and when they are left implicit. [#165](https://github.com/snoyberg/yaml/issues/165)
libyaml/package.yaml+2
@@ -59,4 +59,6 @@ library:
5959 extra-libraries: yaml
6060 - condition: os(windows)
6161 cpp-options: -DWINDOWS
62+ dependencies:
63+ - directory
6264
libyaml/src/Text/Libyaml.hs+11
@@ -7,6 +7,7 @@
77{-# LANGUAGE RankNTypes #-}
88{-# LANGUAGE CPP #-}
99{-# LANGUAGE TypeFamilies #-}
10+{-# LANGUAGE ScopedTypeVariables #-}
1011
1112-- | Low-level, streaming YAML interface. For a higher-level interface, see
1213-- "Data.Yaml".
@@ -69,6 +70,11 @@ import qualified Data.ByteString.Char8 as B8
6970import qualified Data.ByteString.Internal as B
7071import qualified Data.ByteString.Unsafe as BU
7172
73+#if WINDOWS && __GLASGOW_HASKELL__ >= 806
74+import System.Directory (removeFile)
75+import qualified Control.Exception
76+#endif
77+
7278data Event =
7379 EventStreamStart
7480 | EventStreamEnd
@@ -788,6 +794,11 @@ encodeFileWith opts filePath =
788794 bracketP getFile c_fclose $ \file -> runEmitter opts (alloc file) (\u _ -> return u)
789795 where
790796 getFile = do
797+#if WINDOWS && __GLASGOW_HASKELL__ >= 806
798+ -- See: https://github.com/snoyberg/yaml/issues/178#issuecomment-550180027
799+ removeFile filePath `Control.Exception.catch`
800+ (\(_ :: Control.Exception.IOException) -> pure ())
801+#endif
791802 file <- openFile filePath write_flags "w"
792803 if file == nullPtr
793804 then throwIO $ YamlException $ "could not open file for write: " ++ filePath