only read/set the incremental timestamp file once

This commit is contained in:
Joey Hess 2012-09-25 15:45:17 -04:00
parent 7fa916b975
commit 995b04d36f

View file

@ -42,11 +42,11 @@ fromOption = Option.field ['f'] "from" paramRemote "check remote"
startIncrementalOption :: Option startIncrementalOption :: Option
startIncrementalOption = Option.flag ['S'] "incremental" "start an incremental fsck" startIncrementalOption = Option.flag ['S'] "incremental" "start an incremental fsck"
incrementalOption :: Option moreIncrementalOption :: Option
incrementalOption = Option.flag ['m'] "more" "continue an incremental fsck" moreIncrementalOption = Option.flag ['m'] "more" "continue an incremental fsck"
options :: [Option] options :: [Option]
options = [fromOption, startIncrementalOption, incrementalOption] options = [fromOption, startIncrementalOption, moreIncrementalOption]
seek :: [CommandSeek] seek :: [CommandSeek]
seek = seek =
@ -56,12 +56,15 @@ seek =
] ]
withIncremental :: (Incremental -> CommandSeek) -> CommandSeek withIncremental :: (Incremental -> CommandSeek) -> CommandSeek
withIncremental a = withFlag startIncrementalOption $ \startincremental -> withIncremental = withValue $ do
withFlag incrementalOption $ \incremental -> starti <- Annex.getFlag (Option.name startIncrementalOption)
a $ case (startincremental, incremental) of morei <- Annex.getFlag (Option.name moreIncrementalOption)
(False, False) -> NonIncremental case (starti, morei) of
(True, _) -> StartIncremental (False, False) -> return NonIncremental
(False, True) -> ContIncremental (True, _) -> do
recordStartTime
return StartIncremental
(False, True) -> ContIncremental <$> getStartTime
start :: Maybe Remote -> Incremental -> FilePath -> (Key, Backend) -> CommandStart start :: Maybe Remote -> Incremental -> FilePath -> (Key, Backend) -> CommandStart
start from inc file (key, backend) = do start from inc file (key, backend) = do
@ -316,35 +319,28 @@ badContentRemote remote key = do
return $ (if ok then "dropped from " else "failed to drop from ") return $ (if ok then "dropped from " else "failed to drop from ")
++ Remote.name remote ++ Remote.name remote
data Incremental = StartIncremental | ContIncremental | NonIncremental data Incremental = StartIncremental | ContIncremental (Maybe EpochTime) | NonIncremental
deriving (Eq) deriving (Eq)
runFsck :: Incremental -> FilePath -> Key -> Annex Bool -> CommandStart runFsck :: Incremental -> FilePath -> Key -> Annex Bool -> CommandStart
runFsck inc file key a = do runFsck inc file key a = ifM (needFsck inc key)
starttime <- getstart ( do
ifM (needFsck inc starttime key) showStart "fsck" file
( do next $ do
showStart "fsck" file ok <- a
next $ do when ok $
ok <- a recordFsckTime key
when ok $ next $ return ok
recordFsckTime key , stop
next $ return ok )
, stop
)
where
getstart
| inc == StartIncremental = Just <$> recordStartTime
| inc == ContIncremental = getStartTime
| otherwise = return Nothing
{- Check if a key needs to be fscked, with support for incremental fscks. -} {- Check if a key needs to be fscked, with support for incremental fscks. -}
needFsck :: Incremental -> Maybe EpochTime -> Key -> Annex Bool needFsck :: Incremental -> Key -> Annex Bool
needFsck ContIncremental Nothing _ = return True needFsck (ContIncremental Nothing) _ = return True
needFsck ContIncremental starttime key = do needFsck (ContIncremental starttime) key = do
fscktime <- getFsckTime key fscktime <- getFsckTime key
return $ fscktime < starttime return $ fscktime < starttime
needFsck _ _ _ = return True needFsck _ _ = return True
{- To record the time that a key was last fscked, without {- To record the time that a key was last fscked, without
- modifying its mtime, we set the timestamp of its parent directory. - modifying its mtime, we set the timestamp of its parent directory.
@ -374,12 +370,12 @@ getFsckTime key = do
then Just $ modificationTime s then Just $ modificationTime s
else Nothing else Nothing
{- Records the start time of an interactive fsck, also returning it. {- Records the start time of an interactive fsck.
- -
- To guard against time stamp damange (for example, if an annex directory - To guard against time stamp damange (for example, if an annex directory
- is copied without -a), the fsckstate file contains a time that should - is copied without -a), the fsckstate file contains a time that should
- be identical to its modification time. -} - be identical to its modification time. -}
recordStartTime :: Annex (EpochTime) recordStartTime :: Annex ()
recordStartTime = do recordStartTime = do
f <- fromRepo gitAnnexFsckState f <- fromRepo gitAnnexFsckState
createAnnexDirectory $ parentDir f createAnnexDirectory $ parentDir f
@ -389,7 +385,6 @@ recordStartTime = do
t <- modificationTime <$> getFileStatus f t <- modificationTime <$> getFileStatus f
hPutStr h $ showTime $ realToFrac t hPutStr h $ showTime $ realToFrac t
hClose h hClose h
return t
where where
showTime :: POSIXTime -> String showTime :: POSIXTime -> String
showTime = show showTime = show