diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-05-03 16:21:14 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-05-03 16:21:14 +0200 |
commit | ec1f961c4e6ef8a820892648407a2afc31caec6c (patch) | |
tree | 08604a4285abc79e487e2d08cd369fb04e00fed4 /src/Hakyll | |
parent | fbc23ee892b37c0bbc663e2531daa127dd091d30 (diff) | |
download | hakyll-ec1f961c4e6ef8a820892648407a2afc31caec6c.tar.gz |
Close open cache files as soon as possible
See #124
Diffstat (limited to 'src/Hakyll')
-rw-r--r-- | src/Hakyll/Core/Store.hs | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/Hakyll/Core/Store.hs b/src/Hakyll/Core/Store.hs index e3bcce3..1208c84 100644 --- a/src/Hakyll/Core/Store.hs +++ b/src/Hakyll/Core/Store.hs @@ -15,20 +15,22 @@ module Hakyll.Core.Store -------------------------------------------------------------------------------- -import Control.Applicative ((<$>)) -import Control.Exception (IOException, handle) -import qualified Crypto.Hash.MD5 as MD5 -import Data.Binary (Binary, decodeFile, encodeFile) -import qualified Data.ByteString as B -import qualified Data.Cache.LRU.IO as Lru -import Data.List (intercalate) -import qualified Data.Text as T -import qualified Data.Text.Encoding as T -import Data.Typeable (TypeRep, Typeable, cast, typeOf) -import System.Directory (createDirectoryIfMissing) -import System.Directory (doesFileExist, removeFile) -import System.FilePath ((</>)) -import Text.Printf (printf) +import Control.Applicative ((<$>)) +import Control.Exception (IOException, handle) +import qualified Crypto.Hash.MD5 as MD5 +import Data.Binary (Binary, decode, encodeFile) +import qualified Data.ByteString as B +import qualified Data.ByteString.Lazy as BL +import qualified Data.Cache.LRU.IO as Lru +import Data.List (intercalate) +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Typeable (TypeRep, Typeable, cast, typeOf) +import System.Directory (createDirectoryIfMissing) +import System.Directory (doesFileExist, removeFile) +import System.FilePath ((</>)) +import System.IO (IOMode (..), hClose, openFile) +import Text.Printf (printf) -------------------------------------------------------------------------------- @@ -132,7 +134,7 @@ get store identifier = do then return NotFound -- Found in the filesystem else do - v <- decodeFile path + v <- decodeClose cacheInsert store key v return $ Found v -- Found in the in-memory map (or wrong type), just return @@ -141,6 +143,13 @@ get store identifier = do key = hash identifier path = storeDirectory store </> key + -- 'decodeFile' from Data.Binary which closes the file ASAP + decodeClose = do + h <- openFile path ReadMode + lbs <- BL.hGetContents h + BL.length lbs `seq` hClose h + return $ decode lbs + -------------------------------------------------------------------------------- -- | Delete an item |