git.iko.soy/typeable/file-embed
on master help sign in
Use filepath for directory manipulation
commitc7b486b40f7531f3b7d8c03b550055627861bf03 authorMichael Snoyman <michael@snoyman.com> dateSun 30 Dec 2012, 08:31 (14 years ago) parente0add13
4 files changed+13−8
Data/FileEmbed.hs+5−7 file-embed.cabal+2 test/main.hs+5−1 test/sample/bar/baz+1
Data/FileEmbed.hs+5−7
@@ -31,11 +31,11 @@ import System.Directory (doesDirectoryExist, doesFileExist,
3131import Control.Monad (filterM)
3232import qualified Data.ByteString as B
3333import qualified Data.ByteString.Char8 as B8
34−import Control.Arrow ((&&&), second, first)
34+import Control.Arrow ((&&&), second)
3535import Control.Applicative ((<$>))
36−import Data.Monoid (mappend)
3736import Data.ByteString.Unsafe (unsafePackAddressLen)
3837import System.IO.Unsafe (unsafePerformIO)
38+import System.FilePath ((</>))
3939
4040-- | Embed a single file in your source code.
4141--
@@ -90,14 +90,12 @@ notHidden ('.':_) = False
9090notHidden _ = True
9191
9292fileList :: FilePath -> IO [(FilePath, B.ByteString)]
93−fileList top = map (first tail) <$> fileList' top ""
93+fileList top = fileList' top ""
9494
9595fileList' :: FilePath -> FilePath -> IO [(FilePath, B.ByteString)]
9696fileList' realTop top = do
97− let prefix1 = top ++ "/"
98− prefix2 = realTop ++ prefix1
99− allContents <- filter notHidden <$> getDirectoryContents prefix2
100− let all' = map (mappend prefix1 &&& mappend prefix2) allContents
97+ allContents <- filter notHidden <$> getDirectoryContents (realTop </> top)
98+ let all' = map ((top </>) &&& (\x -> realTop </> top </> x)) allContents
10199 files <- filterM (doesFileExist . snd) all' >>=
102100 mapM (liftPair2 . second B.readFile)
103101 dirs <- filterM (doesDirectoryExist . snd) all' >>=
file-embed.cabal+2
@@ -20,6 +20,7 @@ library
2020 , bytestring >= 0.9.1.4
2121 , directory >= 1.0.0.3
2222 , template-haskell
23+ , filepath
2324 exposed-modules: Data.FileEmbed
2425 ghc-options: -Wall
2526
@@ -30,6 +31,7 @@ test-suite test
3031 build-depends: base
3132 , file-embed
3233 , HUnit
34+ , filepath
3335
3436source-repository head
3537 type: git
test/main.hs+5−1
@@ -3,8 +3,12 @@
33
44import Data.FileEmbed
55import Test.HUnit ((@?=))
6+import System.FilePath ((</>))
67
78main :: IO ()
89main = do
910 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