Skip to content

Commit

Permalink
Fixed filename encoding issue in Network.Gitit.Cache.
Browse files Browse the repository at this point in the history
Also simplified some Util code by using Text.Pandoc.UTF8 functions.
  • Loading branch information
jgm committed Mar 20, 2013
1 parent 34bbb04 commit 39d5590
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Network/Gitit/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ import Network.Gitit.State
import Network.Gitit.Types
import Control.Monad
import Control.Monad.Trans (liftIO)
import Codec.Binary.UTF8.String (encodeString)
import Text.Pandoc.UTF8 (encodePath)

-- | Expire a cached file, identified by its filename in the filestore.
-- If there is an associated exported PDF, expire it too.
-- Returns () after deleting a file from the cache, fails if no cached file.
expireCachedFile :: String -> GititServerPart ()
expireCachedFile file = do
cfg <- getConfig
let target = encodeString $ cacheDir cfg </> file
let target = encodePath $ cacheDir cfg </> file
exists <- liftIO $ doesFileExist target
when exists $ liftIO $ do
liftIO $ removeFile target
Expand All @@ -62,7 +62,7 @@ expireCachedPDF file =
lookupCache :: String -> GititServerPart (Maybe (UTCTime, B.ByteString))
lookupCache file = do
cfg <- getConfig
let target = encodeString $ cacheDir cfg </> file
let target = encodePath $ cacheDir cfg </> file
exists <- liftIO $ doesFileExist target
if exists
then liftIO $ do
Expand All @@ -79,7 +79,7 @@ lookupCache file = do
cacheContents :: String -> B.ByteString -> GititServerPart ()
cacheContents file contents = do
cfg <- getConfig
let target = encodeString $ cacheDir cfg </> file
let target = encodePath $ cacheDir cfg </> file
let targetDir = takeDirectory target
liftIO $ do
createDirectoryIfMissing True targetDir
Expand Down
14 changes: 2 additions & 12 deletions Network/Gitit/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,13 @@ import System.FilePath ((</>), (<.>))
import System.IO.Error (isAlreadyExistsError)
import Control.Monad.Trans (liftIO)
import Data.Char (toLower)
import Data.ByteString.Lazy.UTF8 (toString)
import qualified Data.ByteString.Lazy as B
import Network.Gitit.Types
import qualified Control.Exception as E
import Control.Monad (liftM)
#if MIN_VERSION_base(4,5,0)
#else
import Codec.Binary.UTF8.String (encodeString)
#endif
import qualified Text.Pandoc.UTF8 as UTF8

-- | Read file as UTF-8 string. Encode filename as UTF-8.
readFileUTF8 :: FilePath -> IO String
#if MIN_VERSION_base(4,5,0)
readFileUTF8 f = liftM toString $ B.readFile f
#else
readFileUTF8 f = liftM toString $ B.readFile $ encodeString f
#endif
readFileUTF8 = UTF8.readFile

-- | Perform a function a directory and return to working directory.
inDir :: FilePath -> IO a -> IO a
Expand Down

0 comments on commit 39d5590

Please sign in to comment.