Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use binary I/O for cabal files #142

Merged
merged 1 commit into from
Jan 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use binary I/O for cabal files
This makes character encoding of UTF-8 explicit, and avoids problems
when a different system locale is set. For more information, see:
http://www.snoyman.com/blog/2016/12/beware-of-readfile
  • Loading branch information
snoyberg committed Jan 6, 2017
commit 331ab4eacc0223b626d117d3da576a78ccacfe7f
5 changes: 4 additions & 1 deletion hpack.cabal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- This file has been generated from package.yaml by hpack version 0.14.1.
-- This file has been generated from package.yaml by hpack version 0.15.0.
--
-- see: https://github.com/sol/hpack

Expand Down Expand Up @@ -28,6 +28,7 @@ library
build-depends:
base >= 4.7 && < 5
, base-compat >= 0.8
, bytestring
, deepseq
, directory
, filepath
Expand Down Expand Up @@ -59,6 +60,7 @@ executable hpack
build-depends:
base >= 4.7 && < 5
, base-compat >= 0.8
, bytestring
, deepseq
, directory
, filepath
Expand All @@ -82,6 +84,7 @@ test-suite spec
build-depends:
base >= 4.7 && < 5
, base-compat >= 0.8
, bytestring
, deepseq
, directory
, filepath
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ghc-options: -Wall
dependencies:
- base >= 4.7 && < 5
- base-compat >= 0.8
- bytestring
- deepseq
- directory
- filepath
Expand Down
5 changes: 4 additions & 1 deletion src/Hpack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import Prelude.Compat
import Control.DeepSeq
import Control.Exception
import Control.Monad.Compat
import qualified Data.ByteString as B
import Data.List.Compat
import Data.Maybe
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
import Data.Version (Version)
import qualified Data.Version as Version
import System.Environment
Expand Down Expand Up @@ -120,7 +123,7 @@ hpackWithVersionResult v dir = do
if (fmap snd old == Just (lines new)) then
return OutputUnchanged
else do
writeFile cabalFile $ header v ++ new
B.writeFile cabalFile $ encodeUtf8 $ T.pack $ header v ++ new
return Generated
else
return AlreadyGeneratedByNewerHpack
Expand Down