summaryrefslogtreecommitdiff
path: root/Assistant
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-03-05 18:26:53 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-03-05 18:26:53 -0400
commit3118df84f037fe293ba60191b787c6605aa9877f (patch)
treeac75ab92189a1a95e2f6b21fd3e628ee91c2c9d6 /Assistant
parentb21d58eaf55608f4e49b2615319b900d29b9c32f (diff)
assistant: Smarter log file rotation, which takes free disk space into account.
Diffstat (limited to 'Assistant')
-rw-r--r--Assistant/Threads/SanityChecker.hs19
1 files changed, 15 insertions, 4 deletions
diff --git a/Assistant/Threads/SanityChecker.hs b/Assistant/Threads/SanityChecker.hs
index d7fe366e2..d7a71d477 100644
--- a/Assistant/Threads/SanityChecker.hs
+++ b/Assistant/Threads/SanityChecker.hs
@@ -38,6 +38,7 @@ import Assistant.Unused
import Logs.Unused
import Logs.Transfer
import Config.Files
+import Utility.DiskFree
import qualified Annex
#ifdef WITH_WEBAPP
import Assistant.WebApp.Types
@@ -203,17 +204,27 @@ hourlyCheck = do
#endif
#ifndef mingw32_HOST_OS
-{- Rotate logs until log file size is < 1 mb. -}
+{- Rotate logs once when total log file size is > 2 mb.
+ -
+ - If total log size is larger than the amount of free disk space,
+ - continue rotating logs until size is < 2 mb, even if this
+ - results in immediately losing the just logged data.
+ -}
checkLogSize :: Int -> Assistant ()
checkLogSize n = do
f <- liftAnnex $ fromRepo gitAnnexLogFile
logs <- liftIO $ listLogs f
totalsize <- liftIO $ sum <$> mapM filesize logs
- when (totalsize > oneMegabyte) $ do
+ when (totalsize > 2 * oneMegabyte) $ do
notice ["Rotated logs due to size:", show totalsize]
liftIO $ openLog f >>= redirLog
- when (n < maxLogs + 1) $
- checkLogSize $ n + 1
+ when (n < maxLogs + 1) $ do
+ df <- liftIO $ getDiskFree $ takeDirectory f
+ case df of
+ Just free
+ | free < fromIntegral totalsize ->
+ checkLogSize (n + 1)
+ _ -> noop
where
filesize f = fromIntegral . fileSize <$> liftIO (getFileStatus f)