git.iko.soy/typeable/file-embed
on master help sign in
Use filepath for directory manipulation
c7b486bMichael Snoyman
Data/FileEmbed.hs+5−7
@@ -31,11 +31,11 @@ import System.Directory (doesDirectoryExist, doesFileExist,
31import Control.Monad (filterM)
31import Control.Monad (filterM)
32import qualified Data.ByteString as B
32import qualified Data.ByteString as B
33import qualified Data.ByteString.Char8 as B8
33import qualified Data.ByteString.Char8 as B8
34−import Control.Arrow ((&&&), second, first)
34+import Control.Arrow ((&&&), second)
35import Control.Applicative ((<$>))
35import Control.Applicative ((<$>))
36−import Data.Monoid (mappend)
37import Data.ByteString.Unsafe (unsafePackAddressLen)
36import Data.ByteString.Unsafe (unsafePackAddressLen)
38import System.IO.Unsafe (unsafePerformIO)
37import System.IO.Unsafe (unsafePerformIO)
38+import System.FilePath ((</>))
39
39
40-- | Embed a single file in your source code.
40-- | Embed a single file in your source code.
41--
41--
@@ -90,14 +90,12 @@ notHidden ('.':_) = False
90notHidden _ = True
90notHidden _ = True
91
91
92fileList :: FilePath -> IO [(FilePath, B.ByteString)]
92fileList :: FilePath -> IO [(FilePath, B.ByteString)]
93−fileList top = map (first tail) <$> fileList' top ""
93+fileList top = fileList' top ""
94
94
95fileList' :: FilePath -> FilePath -> IO [(FilePath, B.ByteString)]
95fileList' :: FilePath -> FilePath -> IO [(FilePath, B.ByteString)]
96fileList' realTop top = do
96fileList' realTop top = do
97− let prefix1 = top ++ "/"
98− prefix2 = realTop ++ prefix1
99− allContents <- filter notHidden <$> getDirectoryContents prefix2
97+ allContents <- filter notHidden <$> getDirectoryContents (realTop </> top)
100− let all' = map (mappend prefix1 &&& mappend prefix2) allContents
98+ let all' = map ((top </>) &&& (\x -> realTop </> top </> x)) allContents
101 files <- filterM (doesFileExist . snd) all' >>=
99 files <- filterM (doesFileExist . snd) all' >>=
102 mapM (liftPair2 . second B.readFile)
100 mapM (liftPair2 . second B.readFile)
103 dirs <- filterM (doesDirectoryExist . snd) all' >>=
101 dirs <- filterM (doesDirectoryExist . snd) all' >>=
file-embed.cabal+2
@@ -20,6 +20,7 @@ library
20 , bytestring >= 0.9.1.4
20 , bytestring >= 0.9.1.4
21 , directory >= 1.0.0.3
21 , directory >= 1.0.0.3
22 , template-haskell
22 , template-haskell
23+ , filepath
23 exposed-modules: Data.FileEmbed
24 exposed-modules: Data.FileEmbed
24 ghc-options: -Wall
25 ghc-options: -Wall
25
26
@@ -30,6 +31,7 @@ test-suite test
30 build-depends: base
31 build-depends: base
31 , file-embed
32 , file-embed
32 , HUnit
33 , HUnit
34+ , filepath
33
35
34source-repository head
36source-repository head
35 type: git
37 type: git
test/main.hs+5−1
@@ -3,8 +3,12 @@
3
3
4import Data.FileEmbed
4import Data.FileEmbed
5import Test.HUnit ((@?=))
5import Test.HUnit ((@?=))
6+import System.FilePath ((</>))
6
7
7main :: IO ()
8main :: IO ()
8main = do
9main = do
9 let received = $(embedDir "test/sample")
10 let received = $(embedDir "test/sample")
10− received @?= [("foo", "foo\n")]
11+ received @?=
12+ [ ("foo", "foo\n")
13+ , ("bar" </> "baz", "baz\n")
14+ ]
test/sample/bar/baznew file+1
@@ -0,0 +1 @@
1+baz