From 70c7363b8c1ad250c5f68993867015ef68a8b46c Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Fri, 31 Dec 2010 12:18:33 +0100 Subject: Add wasModified method --- src/Hakyll/Core/Store.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Hakyll/Core/Store.hs b/src/Hakyll/Core/Store.hs index 02b9b4e..7e57df2 100644 --- a/src/Hakyll/Core/Store.hs +++ b/src/Hakyll/Core/Store.hs @@ -5,6 +5,7 @@ module Hakyll.Core.Store , makeStore , storeSet , storeGet + , wasModified ) where import Control.Applicative ((<$>)) @@ -15,6 +16,7 @@ import Data.Binary (Binary, encodeFile, decodeFile) import Hakyll.Core.Identifier import Hakyll.Core.Util.File +import Hakyll.Core.ResourceProvider -- | Data structure used for the store -- @@ -51,3 +53,21 @@ storeGet store name identifier = do else return Nothing where path = makePath store name identifier + +-- | Check if a resource was modified +-- +wasModified :: Store -> ResourceProvider -> Identifier -> IO Bool +wasModified store provider identifier = do + -- Get the latest seen digest from the store + lastDigest <- storeGet store itemName identifier + -- Calculate the digest for the resource + newDigest <- resourceDigest provider identifier + -- Check digests + if Just newDigest == lastDigest + -- All is fine, not modified + then return False + -- Resource modified; store new digest + else do storeSet store itemName identifier newDigest + return True + where + itemName = "Hakyll.Core.Store.wasModified" -- cgit v1.2.3