@@ -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