summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Store.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/Core/Store.hs')
-rw-r--r--src/Hakyll/Core/Store.hs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/Hakyll/Core/Store.hs b/src/Hakyll/Core/Store.hs
index e0d6774..7114afc 100644
--- a/src/Hakyll/Core/Store.hs
+++ b/src/Hakyll/Core/Store.hs
@@ -3,6 +3,7 @@
{-# LANGUAGE ExistentialQuantification #-}
module Hakyll.Core.Store
( Store
+ , StoreGet (..)
, makeStore
, storeSet
, storeGet
@@ -25,6 +26,13 @@ import Hakyll.Core.Util.File
--
data Storable = forall a. (Binary a, Typeable a) => Storable a
+-- | Result when an item from the store
+--
+data StoreGet a = Found a
+ | NotFound
+ | WrongType
+ deriving (Show, Eq, Ord)
+
-- | Data structure used for the store
--
data Store = Store
@@ -72,22 +80,24 @@ storeSet store name identifier value = do
-- | Load an item
--
storeGet :: (Binary a, Typeable a)
- => Store -> String -> Identifier -> IO (Maybe a)
+ => Store -> String -> Identifier -> IO (StoreGet a)
storeGet store name identifier = do
-- First check the in-memory map
map' <- readMVar $ storeMap store
case M.lookup path map' of
-- Found in the in-memory map
- Just (Storable s) -> return $ cast s
+ Just (Storable s) -> return $ case cast s of
+ Nothing -> WrongType
+ Just s' -> Found s'
-- Not found in the map, try the filesystem
Nothing -> do
exists <- doesFileExist path
if not exists
-- Not found in the filesystem either
- then return Nothing
+ then return NotFound
-- Found in the filesystem
else do v <- decodeFile path
addToMap store path v
- return $ Just v
+ return $ Found v
where
path = makePath store name identifier