1{- git-annex object content presence, low-level functions
2 -
3 - Copyright 2010-2021 Joey Hess <id@joeyh.name>
4 -
5 - Licensed under the GNU AGPL version 3 or higher.
6 -}
7
8module Annex.Content.Presence.LowLevel where
9
10import Annex.Common
11import Annex.Verify
12import Annex.InodeSentinal
13import Utility.InodeCache
14
15isUnmodifiedLowLevel :: (Key -> [InodeCache] -> Annex ()) -> Key -> RawFilePath -> InodeCache -> [InodeCache] -> Annex Bool
16isUnmodifiedLowLevel addinodecaches key f fc ic =
17	isUnmodifiedCheapLowLevel fc ic <||> expensivecheck
18  where
19	expensivecheck = ifM (verifyKeyContent key f)
20		( do
21			-- The file could have been modified while it was
22			-- being verified. Detect that.
23			ifM (geti >>= maybe (return False) (compareInodeCaches fc))
24				( do
25					-- Update the InodeCache to avoid
26					-- performing this expensive check again.
27					addinodecaches key [fc]
28					return True
29				, return False
30				)
31		, return False
32		)
33	geti = withTSDelta (liftIO . genInodeCache f)
34
35isUnmodifiedCheapLowLevel :: InodeCache -> [InodeCache] -> Annex Bool
36isUnmodifiedCheapLowLevel fc ic = anyM (compareInodeCaches fc) ic
37