aboutsummaryrefslogtreecommitdiff
path: root/Annex/Content
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-12-08 13:13:36 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-12-08 13:13:36 -0400
commit8150faff37b4f6a55a86ea14cd181edede6a8084 (patch)
treeaffc96061102dcf434367d7720807e630223d471 /Annex/Content
parent9c5e49160d8a01d3edcecf3324fd4f1a2bafb72c (diff)
update the cache automatically when moving objects in or out
Diffstat (limited to 'Annex/Content')
-rw-r--r--Annex/Content/Direct.hs26
1 files changed, 18 insertions, 8 deletions
diff --git a/Annex/Content/Direct.hs b/Annex/Content/Direct.hs
index e23c6512c..7ab70e612 100644
--- a/Annex/Content/Direct.hs
+++ b/Annex/Content/Direct.hs
@@ -8,8 +8,8 @@
module Annex.Content.Direct (
associatedFiles,
unmodifed,
- getCache,
- showCache,
+ updateCache,
+ removeCache
) where
import Common.Annex
@@ -39,12 +39,22 @@ associatedFiles key = do
- expected mtime and inode.
-}
unmodifed :: Key -> FilePath -> Annex Bool
-unmodifed key file = do
- cachefile <- inRepo $ gitAnnexCache key
- liftIO $ do
- curr <- getCache file
- old <- catchDefaultIO Nothing $ readCache <$> readFile cachefile
- return $ isJust curr && curr == old
+unmodifed key file = withCacheFile key $ \cachefile -> do
+ curr <- getCache file
+ old <- catchDefaultIO Nothing $ readCache <$> readFile cachefile
+ return $ isJust curr && curr == old
+
+{- Stores a cache of attributes for a file that is associated with a key. -}
+updateCache :: Key -> FilePath -> Annex ()
+updateCache key file = withCacheFile key $ \cachefile ->
+ maybe noop (writeFile cachefile . showCache) =<< getCache file
+
+{- Removes a cache. -}
+removeCache :: Key -> Annex ()
+removeCache key = withCacheFile key nukeFile
+
+withCacheFile :: Key -> (FilePath -> IO a) -> Annex a
+withCacheFile key a = liftIO . a =<< inRepo (gitAnnexCache key)
{- Cache a file's inode, size, and modification time to determine if it's
- been changed. -}