aboutsummaryrefslogtreecommitdiff
path: root/Limit.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-08 13:39:18 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-08 13:39:18 -0400
commit1ccd0ed1e6541534626673dc5dbdd97c9ab9ca49 (patch)
treed640f8081735fc7eb3a81fae4c93df85ddc366c5 /Limit.hs
parent45d50d8c27207fa09e5d3331683e1510df3f3bdd (diff)
Added --smallerthan and --largerthan limits
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