@@ -11,10 +11,8 @@ module WaiAppStatic.Storage.Filesystem
1111 ) where
1212
1313import WaiAppStatic.Types
14−import Prelude hiding (FilePath)
15−import Filesystem.Path.CurrentOS (FilePath, (</>))
16−import qualified Filesystem.Path.CurrentOS as F
17−import qualified Filesystem as F
14+import System.FilePath ((</>))
15+import System.Directory (doesFileExist, doesDirectoryExist, getDirectoryContents)
1816import Data.List (foldl')
1917import Control.Monad (forM)
2018import Util
@@ -29,10 +27,11 @@ import qualified Crypto.Hash.Conduit (hashFile)
2927import Data.Byteable (toBytes)
3028import Crypto.Hash (MD5, Digest)
3129import qualified Data.ByteString.Base64 as B64
30+import qualified Data.Text as T
3231
3332-- | Construct a new path from a root and some @Pieces@.
3433pathFromPieces :: FilePath -> Pieces -> FilePath
35−pathFromPieces = foldl' (\fp p -> fp </> F.fromText (fromPiece p))
34+pathFromPieces = foldl' (\fp p -> fp </> T.unpack (fromPiece p))
3635
3736-- | Settings optimized for a web application. Files will have aggressive
3837-- caching applied and hashes calculated, and indices and listings are disabled.
@@ -86,12 +85,12 @@ fileHelper :: ETagLookup
8685 -> Piece -- ^ file name
8786 -> IO (Maybe File)
8887fileHelper hashFunc fp name = do
89− efs <- try $ getFileStatus $ F.encodeString fp
88+ efs <- try $ getFileStatus fp
9089 case efs of
9190 Left (_ :: SomeException) -> return Nothing
9291 Right fs | isRegularFile fs -> return $ Just File
9392 { fileGetSize = fromIntegral $ fileSize fs
94− , fileToResponse = \s h -> W.responseFile s h (F.encodeString fp) Nothing
93+ , fileToResponse = \s h -> W.responseFile s h fp Nothing
9594 , fileName = name
9695 , fileGetHash = hashFunc fp
9796 , fileGetModified = Just $ modificationTime fs
@@ -117,7 +116,7 @@ webAppLookup hashFunc prefix pieces =
117116-- exists.
118117hashFile :: FilePath -> IO ByteString
119118hashFile fp = do
120− h <- Crypto.Hash.Conduit.hashFile (F.encodeString fp)
119+ h <- Crypto.Hash.Conduit.hashFile fp
121120 return $ B64.encode $ toBytes (h :: Digest MD5)
122121
123122hashFileIfExists :: ETagLookup
@@ -128,12 +127,9 @@ hashFileIfExists fp = do
128127 Right x -> Just x
129128
130129isVisible :: FilePath -> Bool
131−isVisible =
132− go . F.encodeString . F.filename
133− where
134− go ('.':_) = False
135− go "" = False
136− go _ = True
130+isVisible ('.':_) = False
131+isVisible "" = False
132+isVisible _ = True
137133
138134-- | Get a proper @LookupResult@, checking if the path is a file or folder.
139135-- Compare with @webAppLookup@, which only deals with files.
@@ -141,17 +137,18 @@ fileSystemLookup :: ETagLookup
141137 -> FilePath -> Pieces -> IO LookupResult
142138fileSystemLookup hashFunc prefix pieces = do
143139 let fp = pathFromPieces prefix pieces
144− fe <- F.isFile fp
140+ fe <- doesFileExist fp
145141 if fe
146142 then fileHelperLR hashFunc fp lastPiece
147143 else do
148− de <- F.isDirectory fp
144+ de <- doesDirectoryExist fp
149145 if de
150146 then do
151− entries' <- fmap (filter isVisible) $ F.listDirectory fp
152− entries <- forM entries' $ \fp' -> do
153− let name = unsafeToPiece $ either id id $ F.toText $ F.filename fp'
154− de' <- F.isDirectory fp'
147+ entries' <- fmap (filter isVisible) $ getDirectoryContents fp
148+ entries <- forM entries' $ \fpRel' -> do
149+ let name = unsafeToPiece $ T.pack fpRel'
150+ fp' = fp </> fpRel'
151+ de' <- doesDirectoryExist fp'
155152 if de'
156153 then return $ Just $ Left name
157154 else do