summaryrefslogtreecommitdiff
path: root/Limit.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Limit.hs')
-rw-r--r--Limit.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/Limit.hs b/Limit.hs
index de241ba60..54a4bae79 100644
--- a/Limit.hs
+++ b/Limit.hs
@@ -21,8 +21,10 @@ import Annex.Content
import Annex.UUID
import Logs.Trust
import Types.TrustLevel
+import Types.Key
import Logs.Group
import Utility.HumanTime
+import Utility.DataUnits
type MatchFiles = AssumeNotPresent -> FilePath -> Annex Bool
type MkLimit = String -> Either String MatchFiles
@@ -143,6 +145,21 @@ limitInBackend name = Right $ const $ Backend.lookupFile >=> check
wanted = Backend.lookupBackendName name
check = return . maybe False ((==) wanted . snd)
+{- Adds a limit to skip files that are too large or too small -}
+addLargerThan :: String -> Annex ()
+addLargerThan = addLimit . limitSize (>)
+
+addSmallerThan :: String -> Annex ()
+addSmallerThan = addLimit . limitSize (<)
+
+limitSize :: (Maybe Integer -> Maybe Integer -> Bool) -> MkLimit
+limitSize vs s = case readSize dataUnits s of
+ Nothing -> Left "bad size"
+ Just sz -> Right $ const $ Backend.lookupFile >=> check sz
+ where
+ check _ Nothing = return False
+ check sz (Just (key, _)) = return $ keySize key `vs` Just sz
+
addTimeLimit :: String -> Annex ()
addTimeLimit s = do
let seconds = fromMaybe (error "bad time-limit") $ parseDuration s