@@ -3,6 +3,7 @@
33{-# LANGUAGE ExistentialQuantification #-}
44module Hakyll.Core.Store
55 ( Store
6+ , StoreGet (..)
67 , makeStore
78 , storeSet
89 , storeGet
@@ -25,6 +26,13 @@ import Hakyll.Core.Util.File
2526--
2627data Storable = forall a. (Binary a, Typeable a) => Storable a
2728
29+-- | Result when an item from the store
30+--
31+data StoreGet a = Found a
32+ | NotFound
33+ | WrongType
34+ deriving (Show, Eq, Ord)
35+
2836-- | Data structure used for the store
2937--
3038data Store = Store
@@ -72,22 +80,24 @@ storeSet store name identifier value = do
7280-- | Load an item
7381--
7482storeGet :: (Binary a, Typeable a)
75− => Store -> String -> Identifier -> IO (Maybe a)
83+ => Store -> String -> Identifier -> IO (StoreGet a)
7684storeGet store name identifier = do
7785 -- First check the in-memory map
7886 map' <- readMVar $ storeMap store
7987 case M.lookup path map' of
8088 -- Found in the in-memory map
81− Just (Storable s) -> return $ cast s
89+ Just (Storable s) -> return $ case cast s of
90+ Nothing -> WrongType
91+ Just s' -> Found s'
8292 -- Not found in the map, try the filesystem
8393 Nothing -> do
8494 exists <- doesFileExist path
8595 if not exists
8696 -- Not found in the filesystem either
87− then return Nothing
97+ then return NotFound
8898 -- Found in the filesystem
8999 else do v <- decodeFile path
90100 addToMap store path v
91− return $ Just v
101+ return $ Found v
92102 where
93103 path = makePath store name identifier