Directory listings are sorted yesodweb/yesod#1684

This commit is contained in:
Michael Snoyman 2020-07-01 10:41:12 +03:00
parent 60a0adc5e5
commit a3c24307c8
No known key found for this signature in database
GPG Key ID: 907EAE2F42B52046
4 changed files with 10 additions and 4 deletions

View File

@ -1,5 +1,9 @@
# ChangeLog for file-embed
## 0.0.13.0
* Ensure that directory listings are returned in sorted order for reproducibility [yesodweb/yesod#1684](https://github.com/yesodweb/yesod/issues/1684)
## 0.0.12.0
* Use the `Bytes` literal on newer GHCs to reduce memory usage during compilation [#36](https://github.com/snoyberg/file-embed/pull/36)

View File

@ -71,6 +71,8 @@ import System.IO.Unsafe (unsafePerformIO)
import System.FilePath ((</>), takeDirectory, takeExtension)
import Data.String (fromString)
import Prelude as P
import Data.List (sortBy)
import Data.Ord (comparing)
-- | Embed a single file in your source code.
--
@ -234,7 +236,7 @@ fileList' realTop top = do
mapM (liftPair2 . second B.readFile)
dirs <- filterM (doesDirectoryExist . snd) all' >>=
mapM (fileList' realTop . fst)
return $ concat $ files : dirs
return $ sortBy (comparing fst) $ concat $ files : dirs
liftPair2 :: Monad m => (a, m b) -> m (a, b)
liftPair2 (a, b) = b >>= \b' -> return (a, b')

View File

@ -1,5 +1,5 @@
name: file-embed
version: 0.0.12.0
version: 0.0.13.0
license: BSD3
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>

View File

@ -14,8 +14,8 @@ main :: IO ()
main = do
let received = $(embedDir "test/sample")
received @?=
[ ("foo", "foo\r\n")
, ("bar" </> "baz", "baz\r\n")
[ ("bar" </> "baz", "baz\r\n")
, ("foo", "foo\r\n")
]
let str = $(embedStringFile "test/sample/foo") :: String
filter (/= '\r') str @?= "foo\n"