1--------------------------------------------------------------------------------
2module Hakyll.Core.Resource.Modified
4 , resourceModificationTime
8--------------------------------------------------------------------------------
9import Control.Applicative ((<$>), (<*>))
10import Control.Monad (when)
11import qualified Crypto.Hash.MD5 as MD5
12import qualified Data.ByteString as B
13import qualified Data.ByteString.Lazy as BL
15import qualified Data.Map as M
16import Data.Time (UTCTime)
17import System.Directory (getModificationTime)
20--------------------------------------------------------------------------------
21import Hakyll.Core.Resource
22import Hakyll.Core.Resource.MetadataCache
23import Hakyll.Core.Resource.Provider.Internal
24import Hakyll.Core.Store (Store)
25import qualified Hakyll.Core.Store as Store
28--------------------------------------------------------------------------------
29-- | A resource is modified if it or its metadata has changed
30resourceModified :: ResourceProvider -> Resource -> IO Bool
32 | not exists = return False
34 cache <- readIORef cacheRef
35 case M.lookup r cache of
38 -- Check if the actual file was modified, and do a recursive
39 -- call to check if the metadata file was modified
41 <$> fileDigestModified store (unResource r)
42 <*> resourceModified rp (resourceMetadataResource r)
43 modifyIORef cacheRef (M.insert r m)
46 when m $ resourceInvalidateMetadataCache rp r
50 exists = resourceExists rp r
51 store = resourceStore rp
52 cacheRef = resourceModifiedCache rp
55--------------------------------------------------------------------------------
56-- | Utility: Check if a the digest of a file was modified
57fileDigestModified :: Store -> FilePath -> IO Bool
58fileDigestModified store fp = do
59 -- Get the latest seen digest from the store, and calculate the current
61 lastDigest <- Store.get store key
62 newDigest <- fileDigest fp
63 if Store.Found newDigest == lastDigest
64 -- All is fine, not modified
66 -- Resource modified; store new digest
68 Store.set store key newDigest
71 key = ["Hakyll.Core.Resource.Provider.fileModified", fp]
74--------------------------------------------------------------------------------
75-- | Utility: Retrieve a digest for a given file
76fileDigest :: FilePath -> IO B.ByteString
77fileDigest = fmap MD5.hashlazy . BL.readFile
80--------------------------------------------------------------------------------
81resourceModificationTime :: Resource -> IO UTCTime
82resourceModificationTime = getModificationTime . unResource
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list