diff options
author | Joey Hess <joey@kitenet.net> | 2012-10-08 13:39:18 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-10-08 13:39:18 -0400 |
commit | 1ccd0ed1e6541534626673dc5dbdd97c9ab9ca49 (patch) | |
tree | d640f8081735fc7eb3a81fae4c93df85ddc366c5 /Limit.hs | |
parent | 45d50d8c27207fa09e5d3331683e1510df3f3bdd (diff) |
Added --smallerthan and --largerthan limits
Diffstat (limited to 'Limit.hs')
-rw-r--r-- | Limit.hs | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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 |