on master help sign in
Add O_TRUNC when opening a file CC @Blaisorblade
64bf822Michael Snoyman
ChangeLog.md+4
@@ -1,3 +1,7 @@
1+## 0.8.18.7
2+
3+* Add `O_TRUNC` when opening files
4+
1## 0.8.18.6
5## 0.8.18.6
2
6
3* s/fdopen/_fdopen on Windows [#96](https://github.com/snoyberg/yaml/issues/96)
7* s/fdopen/_fdopen on Windows [#96](https://github.com/snoyberg/yaml/issues/96)
Text/Libyaml.hs+1−1
@@ -511,7 +511,7 @@ decode bs =
511-- XXX copied from GHC.IO.FD
511-- XXX copied from GHC.IO.FD
512std_flags, read_flags, output_flags, write_flags :: CInt
512std_flags, read_flags, output_flags, write_flags :: CInt
513std_flags = Posix.o_NOCTTY
513std_flags = Posix.o_NOCTTY
514−output_flags = std_flags .|. Posix.o_CREAT
514+output_flags = std_flags .|. Posix.o_CREAT .|. Posix.o_TRUNC
515read_flags = std_flags .|. Posix.o_RDONLY
515read_flags = std_flags .|. Posix.o_RDONLY
516write_flags = output_flags .|. Posix.o_WRONLY
516write_flags = output_flags .|. Posix.o_WRONLY
517
517
test/Data/YamlSpec.hs+13
@@ -34,6 +34,8 @@ import Data.Vector (Vector)
34import qualified Data.Vector as V
34import qualified Data.Vector as V
35import Data.HashMap.Strict (HashMap)
35import Data.HashMap.Strict (HashMap)
36import qualified Data.HashMap.Strict as HM
36import qualified Data.HashMap.Strict as HM
37+import System.IO (hClose)
38+import System.IO.Temp (withSystemTempFile)
37
39
38data TestJSON = TestJSON
40data TestJSON = TestJSON
39 { string :: Text
41 { string :: Text
@@ -152,6 +154,8 @@ spec = do
152
154
153 it "preserves Scientific precision" casePreservesScientificPrecision
155 it "preserves Scientific precision" casePreservesScientificPrecision
154
156
157+ it "truncates files" caseTruncatesFiles
158+
155
159
156specialStrings :: [T.Text]
160specialStrings :: [T.Text]
157specialStrings =
161specialStrings =
@@ -502,3 +506,12 @@ casePreservesScientificPrecision = do
502 -- results, because of <https://github.com/bos/text/issues/34>.
506 -- results, because of <https://github.com/bos/text/issues/34>.
503 D.decodeEither "x: 9.78159610558926e-5" @?= Right (object
507 D.decodeEither "x: 9.78159610558926e-5" @?= Right (object
504 [ "x" .= D.Number (read "9.78159610558926e-5") ])
508 [ "x" .= D.Number (read "9.78159610558926e-5") ])
509+
510+caseTruncatesFiles :: Assertion
511+caseTruncatesFiles = withSystemTempFile "truncate.yaml" $ \fp h -> do
512+ replicateM_ 500 $ B8.hPut h "HELLO WORLD!!!!!\n"
513+ hClose h
514+ let val = object ["hello" .= ("world" :: String)]
515+ D.encodeFile fp val
516+ res <- D.decodeFileEither fp
517+ either (Left . show) Right res `shouldBe` Right val
yaml.cabal+2−1
@@ -1,5 +1,5 @@
1name: yaml
1name: yaml
2−version: 0.8.18.6
2+version: 0.8.18.7
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
@@ -139,6 +139,7 @@ test-suite spec
139 , aeson-qq
139 , aeson-qq
140 , mockery
140 , mockery
141 , base-compat
141 , base-compat
142+ , temporary
142 ghc-options: -Wall
143 ghc-options: -Wall
143
144
144executable examples
145executable examples