Permalink
Browse files

Use filepath for directory manipulation

  • Loading branch information...
1 parent e0add13 commit c7b486b40f7531f3b7d8c03b550055627861bf03 @snoyberg committed Dec 30, 2012
Showing with 13 additions and 8 deletions.
  1. +5 −7 Data/FileEmbed.hs
  2. +2 −0 file-embed.cabal
  3. +5 −1 test/main.hs
  4. +1 −0 test/sample/bar/baz
View
@@ -31,11 +31,11 @@ import System.Directory (doesDirectoryExist, doesFileExist,
import Control.Monad (filterM)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as B8
-import Control.Arrow ((&&&), second, first)
+import Control.Arrow ((&&&), second)
import Control.Applicative ((<$>))
-import Data.Monoid (mappend)
import Data.ByteString.Unsafe (unsafePackAddressLen)
import System.IO.Unsafe (unsafePerformIO)
+import System.FilePath ((</>))
-- | Embed a single file in your source code.
--
@@ -90,14 +90,12 @@ notHidden ('.':_) = False
notHidden _ = True
fileList :: FilePath -> IO [(FilePath, B.ByteString)]
-fileList top = map (first tail) <$> fileList' top ""
+fileList top = fileList' top ""
fileList' :: FilePath -> FilePath -> IO [(FilePath, B.ByteString)]
fileList' realTop top = do
- let prefix1 = top ++ "/"
- prefix2 = realTop ++ prefix1
- allContents <- filter notHidden <$> getDirectoryContents prefix2
- let all' = map (mappend prefix1 &&& mappend prefix2) allContents
+ allContents <- filter notHidden <$> getDirectoryContents (realTop </> top)
+ let all' = map ((top </>) &&& (\x -> realTop </> top </> x)) allContents
files <- filterM (doesFileExist . snd) all' >>=
mapM (liftPair2 . second B.readFile)
dirs <- filterM (doesDirectoryExist . snd) all' >>=
View
@@ -20,6 +20,7 @@ library
, bytestring >= 0.9.1.4
, directory >= 1.0.0.3
, template-haskell
+ , filepath
exposed-modules: Data.FileEmbed
ghc-options: -Wall
@@ -30,6 +31,7 @@ test-suite test
build-depends: base
, file-embed
, HUnit
+ , filepath
source-repository head
type: git
View
@@ -3,8 +3,12 @@
import Data.FileEmbed
import Test.HUnit ((@?=))
+import System.FilePath ((</>))
main :: IO ()
main = do
let received = $(embedDir "test/sample")
- received @?= [("foo", "foo\n")]
+ received @?=
+ [ ("foo", "foo\n")
+ , ("bar" </> "baz", "baz\n")
+ ]
View
@@ -0,0 +1 @@
+baz

0 comments on commit c7b486b

Please sign in to comment.