summaryrefslogtreecommitdiff
path: root/Limit.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-08 15:18:58 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-08 15:18:58 -0400
commitc452c70ef88197b152c1552563daa6a79e88e91f (patch)
tree27b2031fdb79d183a8abef7ca837cb25a0ecd3a0 /Limit.hs
parent1ccd0ed1e6541534626673dc5dbdd97c9ab9ca49 (diff)
add --ingroup limit
Diffstat (limited to 'Limit.hs')
-rw-r--r--Limit.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/Limit.hs b/Limit.hs
index 54a4bae79..f9e8de270 100644
--- a/Limit.hs
+++ b/Limit.hs
@@ -11,6 +11,7 @@ import Text.Regex.PCRE.Light.Char8
import System.Path.WildMatch
import Data.Time.Clock.POSIX
import qualified Data.Set as S
+import qualified Data.Map as M
import Common.Annex
import qualified Annex
@@ -22,6 +23,7 @@ import Annex.UUID
import Logs.Trust
import Types.TrustLevel
import Types.Key
+import Types.Group
import Logs.Group
import Utility.HumanTime
import Utility.DataUnits
@@ -135,6 +137,28 @@ limitCopies want = case split ":" want of
checktrust t u = (== t) <$> lookupTrust u
checkgroup g u = S.member g <$> lookupGroups u
+{- Adds a limit to skip files not believed to be present in all
+ - repositories in the specified group. -}
+addInGroup :: String -> Annex ()
+addInGroup groupname = do
+ m <- groupMap
+ addLimit $ limitInGroup m groupname
+
+limitInGroup :: GroupMap -> MkLimit
+limitInGroup m groupname
+ | S.null want = Right $ const $ const $ return True
+ | otherwise = Right $ \notpresent ->
+ Backend.lookupFile >=> check notpresent
+ where
+ want = fromMaybe S.empty $ M.lookup groupname $ uuidsByGroup m
+ check _ Nothing = return False
+ check notpresent (Just (key, _))
+ -- optimisation: Check if a wanted uuid is notpresent.
+ | not (S.null (S.intersection want notpresent)) = return False
+ | otherwise = do
+ present <- S.fromList <$> Remote.keyLocations key
+ return $ S.null $ want `S.difference` present
+
{- Adds a limit to skip files not using a specified key-value backend. -}
addInBackend :: String -> Annex ()
addInBackend = addLimit . limitInBackend