summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-09-25 19:37:34 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-09-25 19:37:34 -0400
commit56a96a46d06c9dbe105c8252ee36aae4cba0c628 (patch)
tree4e28e661486bf258635d1e4de592a852ff321794 /Command
parent3526a1cd3b42357e9175f10a90bd83e50021f006 (diff)
fsck: New --incremental-restart option which is nice for scheduling eg, monthly incremental fsck runs in cron jobs.
Diffstat (limited to 'Command')
-rw-r--r--Command/Fsck.hs42
1 files changed, 37 insertions, 5 deletions
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index 3f13140d0..479bca6ef 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -25,6 +25,7 @@ import Utility.FileMode
import Config
import qualified Option
import Types.Key
+import Utility.HumanTime
import System.Posix.Process (getProcessID)
import Data.Time.Clock.POSIX
@@ -45,8 +46,17 @@ startIncrementalOption = Option.flag ['S'] "incremental" "start an incremental f
moreIncrementalOption :: Option
moreIncrementalOption = Option.flag ['m'] "more" "continue an incremental fsck"
+incrementalRestartOption :: Option
+incrementalRestartOption = Option.field [] "incremental-restart" paramTime
+ "schedule an incremental fsck"
+
options :: [Option]
-options = [fromOption, startIncrementalOption, moreIncrementalOption]
+options =
+ [ fromOption
+ , startIncrementalOption
+ , moreIncrementalOption
+ , incrementalRestartOption
+ ]
seek :: [CommandSeek]
seek =
@@ -57,14 +67,33 @@ seek =
withIncremental :: (Incremental -> CommandSeek) -> CommandSeek
withIncremental = withValue $ do
+ i <- maybe (return False) (checkrestart . parseDuration)
+ =<< Annex.getField (Option.name incrementalRestartOption)
starti <- Annex.getFlag (Option.name startIncrementalOption)
morei <- Annex.getFlag (Option.name moreIncrementalOption)
- case (starti, morei) of
- (False, False) -> return NonIncremental
- (True, _) -> do
+ case (i, starti, morei) of
+ (False, False, False) -> return NonIncremental
+ (False, True, _) -> startIncremental
+ (False ,False, True) -> ContIncremental <$> getStartTime
+ (True, _, _) ->
+ maybe startIncremental (return . ContIncremental . Just)
+ =<< getStartTime
+ where
+ startIncremental = do
recordStartTime
return StartIncremental
- (False, True) -> ContIncremental <$> getStartTime
+
+ checkrestart Nothing = error "bad --incremental-restart value"
+ checkrestart (Just delta) = do
+ Annex.addCleanup "" $ do
+ v <- getStartTime
+ case v of
+ Nothing -> noop
+ Just started -> do
+ now <- liftIO getPOSIXTime
+ when (now - realToFrac started >= delta) $
+ resetStartTime
+ return True
start :: Maybe Remote -> Incremental -> FilePath -> (Key, Backend) -> CommandStart
start from inc file (key, backend) = do
@@ -389,6 +418,9 @@ recordStartTime = do
showTime :: POSIXTime -> String
showTime = show
+resetStartTime :: Annex ()
+resetStartTime = liftIO . nukeFile =<< fromRepo gitAnnexFsckState
+
{- Gets the incremental fsck start time. -}
getStartTime :: Annex (Maybe EpochTime)
getStartTime = do