aboutsummaryrefslogtreecommitdiff
path: root/Limit.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-09-25 16:48:24 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-09-25 16:48:24 -0400
commit51d5e6b4c716847dc544fa2d56bbe4567f1bfaf4 (patch)
treea13a562265b76a756c1d18b66cc0a194902a0dfb /Limit.hs
parent067974202e285bc8d0840c2c64e9b84fc52c7c21 (diff)
New --time-limit option, makes long git-annex commands stop after a specified amount of time.
Diffstat (limited to 'Limit.hs')
-rw-r--r--Limit.hs16
1 files changed, 16 insertions, 0 deletions
diff --git a/Limit.hs b/Limit.hs
index 217f38739..babd1c00c 100644
--- a/Limit.hs
+++ b/Limit.hs
@@ -9,6 +9,7 @@ module Limit where
import Text.Regex.PCRE.Light.Char8
import System.Path.WildMatch
+import Data.Time.Clock.POSIX
import Common.Annex
import qualified Annex
@@ -17,6 +18,7 @@ import qualified Remote
import qualified Backend
import Annex.Content
import Logs.Trust
+import Utility.HumanTime
type Limit = Utility.Matcher.Token (FilePath -> Annex Bool)
@@ -106,3 +108,17 @@ addInBackend name = addLimit $ Backend.lookupFile >=> check
where
wanted = Backend.lookupBackendName name
check = return . maybe False ((==) wanted . snd)
+
+addTimeLimit :: String -> Annex ()
+addTimeLimit s = do
+ let seconds = fromMaybe (error "bad time-limit") $ parseDuration s
+ start <- liftIO getPOSIXTime
+ let cutoff = start + seconds
+ addLimit $ const $ do
+ now <- liftIO getPOSIXTime
+ if now > cutoff
+ then do
+ warning $ "Time limit (" ++ s ++ ") reached!"
+ liftIO $ exitWith $ ExitFailure 101
+ else return True
+