only create inode sentinal file when initializing a new repo

This commit is contained in:
Joey Hess 2013-02-20 13:55:53 -04:00
parent af1da07302
commit 6f9be431e6
2 changed files with 42 additions and 19 deletions

View file

@ -17,6 +17,8 @@ module Annex.Content.Direct (
sameInodeCache, sameInodeCache,
removeInodeCache, removeInodeCache,
toInodeCache, toInodeCache,
inodesChanged,
createInodeSentinalFile,
) where ) where
import Common.Annex import Common.Annex
@ -146,26 +148,45 @@ sameInodeCache file (Just old) = go =<< liftIO (genInodeCache file)
{- Some filesystems get new inodes each time they are mounted. {- Some filesystems get new inodes each time they are mounted.
- In order to work on such a filesystem, a sentinal file is used to detect - In order to work on such a filesystem, a sentinal file is used to detect
- when the inodes have changed. -} - when the inodes have changed.
-
- If the sentinal file does not exist, we have to assume that the
- inodes have changed.
-}
inodesChanged :: Annex Bool inodesChanged :: Annex Bool
inodesChanged = maybe calc return =<< Annex.getState Annex.inodeschanged inodesChanged = maybe calc return =<< Annex.getState Annex.inodeschanged
where where
calc = do calc = do
sentinalfile <- fromRepo gitAnnexInodeSentinal scache <- liftIO . genInodeCache
sentinalcachefile <- fromRepo gitAnnexInodeSentinalCache =<< fromRepo gitAnnexInodeSentinal
scache <- liftIO $ genInodeCache sentinalfile scached <- readInodeSentinalFile
scached <- liftIO $ catchMaybeIO $ readInodeCache <$> readFile sentinalcachefile let changed = case (scache, scached) of
case (scache, scached) of (Just c1, Just c2) -> c1 /= c2
(Just c1, Just (Just c2)) -> changed $ c1 /= c2 _ -> True
_ -> do Annex.changeState $ \s -> s { Annex.inodeschanged = Just changed }
writesentinal return changed
changed True
changed v = do readInodeSentinalFile :: Annex (Maybe InodeCache)
Annex.changeState $ \s -> s { Annex.inodeschanged = Just v } readInodeSentinalFile = do
return v sentinalcachefile <- fromRepo gitAnnexInodeSentinalCache
writesentinal = do liftIO $ catchDefaultIO Nothing $
sentinalfile <- fromRepo gitAnnexInodeSentinal readInodeCache <$> readFile sentinalcachefile
sentinalcachefile <- fromRepo gitAnnexInodeSentinalCache
liftIO $ writeFile sentinalfile "" writeInodeSentinalFile :: Annex ()
liftIO $ maybe noop (writeFile sentinalcachefile . showInodeCache) writeInodeSentinalFile = do
=<< genInodeCache sentinalfile sentinalfile <- fromRepo gitAnnexInodeSentinal
sentinalcachefile <- fromRepo gitAnnexInodeSentinalCache
liftIO $ writeFile sentinalfile ""
liftIO $ maybe noop (writeFile sentinalcachefile . showInodeCache)
=<< genInodeCache sentinalfile
{- The sentinal file is only created when first initializing a repository.
- If there are any annexed objects in the repository already, creating
- the file would invalidate their inode caches. -}
createInodeSentinalFile :: Annex ()
createInodeSentinalFile =
unlessM (alreadyexists <||> hasobjects)
writeInodeSentinalFile
where
alreadyexists = isJust <$> readInodeSentinalFile
hasobjects = liftIO . doesDirectoryExist =<< fromRepo gitAnnexObjectDir

View file

@ -27,6 +27,7 @@ import Utility.Shell
import Utility.FileMode import Utility.FileMode
import Config import Config
import Annex.Direct import Annex.Direct
import Annex.Content.Direct
import Backend import Backend
genDescription :: Maybe String -> Annex String genDescription :: Maybe String -> Annex String
@ -45,6 +46,7 @@ initialize mdescription = do
Annex.Branch.create Annex.Branch.create
setVersion setVersion
gitPreCommitHookWrite gitPreCommitHookWrite
createInodeSentinalFile
u <- getUUID u <- getUUID
describeUUID u =<< genDescription mdescription describeUUID u =<< genDescription mdescription