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
=<< fromRepo gitAnnexInodeSentinal
scached <- readInodeSentinalFile
let changed = case (scache, scached) of
(Just c1, Just c2) -> c1 /= c2
_ -> True
Annex.changeState $ \s -> s { Annex.inodeschanged = Just changed }
return changed
readInodeSentinalFile :: Annex (Maybe InodeCache)
readInodeSentinalFile = do
sentinalcachefile <- fromRepo gitAnnexInodeSentinalCache sentinalcachefile <- fromRepo gitAnnexInodeSentinalCache
scache <- liftIO $ genInodeCache sentinalfile liftIO $ catchDefaultIO Nothing $
scached <- liftIO $ catchMaybeIO $ readInodeCache <$> readFile sentinalcachefile readInodeCache <$> readFile sentinalcachefile
case (scache, scached) of
(Just c1, Just (Just c2)) -> changed $ c1 /= c2 writeInodeSentinalFile :: Annex ()
_ -> do writeInodeSentinalFile = do
writesentinal
changed True
changed v = do
Annex.changeState $ \s -> s { Annex.inodeschanged = Just v }
return v
writesentinal = do
sentinalfile <- fromRepo gitAnnexInodeSentinal sentinalfile <- fromRepo gitAnnexInodeSentinal
sentinalcachefile <- fromRepo gitAnnexInodeSentinalCache sentinalcachefile <- fromRepo gitAnnexInodeSentinalCache
liftIO $ writeFile sentinalfile "" liftIO $ writeFile sentinalfile ""
liftIO $ maybe noop (writeFile sentinalcachefile . showInodeCache) liftIO $ maybe noop (writeFile sentinalcachefile . showInodeCache)
=<< genInodeCache sentinalfile =<< 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