summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-12-31 12:18:33 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-12-31 12:18:33 +0100
commit70c7363b8c1ad250c5f68993867015ef68a8b46c (patch)
tree429bab77ed70027d0e8bd5886900a688ac2abe3f /src/Hakyll/Core
parent7b84181dab7c45c48be5db5b68e31ad5880b05cc (diff)
downloadhakyll-70c7363b8c1ad250c5f68993867015ef68a8b46c.tar.gz
Add wasModified method
Diffstat (limited to 'src/Hakyll/Core')
-rw-r--r--src/Hakyll/Core/Store.hs20
1 files changed, 20 insertions, 0 deletions
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"