aboutsummaryrefslogtreecommitdiff
path: root/Command/Fsck.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-31 16:00:13 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-31 16:01:54 -0400
commitdbe6b403da47172346b2536b50a379e6d9b76e31 (patch)
tree2e1db476752b4431578d61c57e1851cd5def2629 /Command/Fsck.hs
parent9a01e2699598ab7affd7c19058bb2a6dad6d3a16 (diff)
Improve shutdown due to --time-limit, especially for fsck
* Perform a clean shutdown when --time-limit is reached. This includes running queued git commands, and cleanup actions normally run when a command is finished. * fsck: Commit incremental fsck database when --time-limit is reached. Previously, some of the last files fscked did not make it into the database when using --time-limit. Note that this changes Annex.addCleanup hooks, to run after --time-limit expires. Fsck was using such a hook to clean up after a --incremental-schedule, and that shouldn't run when --time-limit exipires it. So, instead, moved that cleanup code to be run by cleanupIncremental. Resulted in some data type juggling.
Diffstat (limited to 'Command/Fsck.hs')
-rw-r--r--Command/Fsck.hs52
1 files changed, 30 insertions, 22 deletions
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index a201c4519..c3b73edb5 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -457,18 +457,12 @@ runFsck inc file key a = ifM (needFsck inc key)
{- Check if a key needs to be fscked, with support for incremental fscks. -}
needFsck :: Incremental -> Key -> Annex Bool
+needFsck (ScheduleIncremental _ _ i) k = needFsck i k
#ifdef WITH_DATABASE
needFsck (ContIncremental h) key = liftIO $ not <$> FsckDb.inDb h key
#endif
needFsck _ _ = return True
-#ifdef WITH_DATABASE
-withFsckDb :: Incremental -> (FsckDb.FsckHandle -> Annex ()) -> Annex ()
-withFsckDb (ContIncremental h) a = a h
-withFsckDb (StartIncremental h) a = a h
-withFsckDb NonIncremental _ = noop
-#endif
-
recordFsckTime :: Incremental -> Key -> Annex ()
#ifdef WITH_DATABASE
recordFsckTime inc key = withFsckDb inc $ \h -> liftIO $ FsckDb.addDb h key
@@ -527,7 +521,8 @@ data Incremental
= NonIncremental
#ifdef WITH_DATABASE
| StartIncremental FsckDb.FsckHandle
- | ContIncremental FsckDb.FsckHandle
+ | ContIncremental FsckDb.FsckHandle
+ | ScheduleIncremental Duration UUID Incremental
#endif
prepIncremental :: UUID -> Maybe IncrementalOpt -> Annex Incremental
@@ -536,31 +531,44 @@ prepIncremental _ Nothing = pure NonIncremental
prepIncremental u (Just StartIncrementalO) = do
recordStartTime u
ifM (FsckDb.newPass u)
- ( StartIncremental <$> FsckDb.openDb u
+ ( StartIncremental <$> openFsckDb u
, error "Cannot start a new --incremental fsck pass; another fsck process is already running."
)
prepIncremental u (Just MoreIncrementalO) =
- ContIncremental <$> FsckDb.openDb u
+ ContIncremental <$> openFsckDb u
prepIncremental u (Just (ScheduleIncrementalO delta)) = do
- Annex.addCleanup FsckCleanup $ do
- v <- getStartTime u
- case v of
- Nothing -> noop
- Just started -> do
- now <- liftIO getPOSIXTime
- when (now - realToFrac started >= durationToPOSIXTime delta) $
- resetStartTime u
started <- getStartTime u
- prepIncremental u $ Just $ case started of
+ i <- prepIncremental u $ Just $ case started of
Nothing -> StartIncrementalO
Just _ -> MoreIncrementalO
+ return (ScheduleIncremental delta u i)
#else
prepIncremental _ _ = error "This git-annex was not built with database support; incremental fsck not supported"
#endif
cleanupIncremental :: Incremental -> Annex ()
-#ifdef WITH_DATABASE
-cleanupIncremental i = withFsckDb i FsckDb.closeDb
-#else
+cleanupIncremental (ScheduleIncremental delta u i) = do
+ v <- getStartTime u
+ case v of
+ Nothing -> noop
+ Just started -> do
+ now <- liftIO getPOSIXTime
+ when (now - realToFrac started >= durationToPOSIXTime delta) $
+ resetStartTime u
+ cleanupIncremental i
cleanupIncremental _ = return ()
+
+#ifdef WITH_DATABASE
+openFsckDb :: UUID -> Annex FsckDb.FsckHandle
+openFsckDb u = do
+ h <- FsckDb.openDb u
+ Annex.addCleanup FsckCleanup $
+ FsckDb.closeDb h
+ return h
+
+withFsckDb :: Incremental -> (FsckDb.FsckHandle -> Annex ()) -> Annex ()
+withFsckDb (ContIncremental h) a = a h
+withFsckDb (StartIncremental h) a = a h
+withFsckDb NonIncremental _ = noop
+withFsckDb (ScheduleIncremental _ _ i) a = withFsckDb i a
#endif