summaryrefslogtreecommitdiff
path: root/Limit.hs
diff options
context:
space:
mode:
authorGravatar Nicolas Pouillard <nicolas.pouillard@gmail.com>2012-09-23 19:50:31 +0200
committerGravatar Nicolas Pouillard <nicolas.pouillard@gmail.com>2012-09-23 19:57:21 +0200
commitf0bcc77fb245c5fccadff728fd816471fd9993bf (patch)
tree2a306cca28917c7a25c6079cc6418074af5c391f /Limit.hs
parentc9b3b8829dc3f106583fb933808179ec02773790 (diff)
Limiting the number of copies per trustlevel
The --copies flag now takes an argument of the form: trustlevel:number or number If a trust level is specified the command is limited to files with at least 'number' copies of this 'trustlevel'.
Diffstat (limited to 'Limit.hs')
-rw-r--r--Limit.hs18
1 files changed, 12 insertions, 6 deletions
diff --git a/Limit.hs b/Limit.hs
index 0db418e6c..57d6ebf65 100644
--- a/Limit.hs
+++ b/Limit.hs
@@ -16,6 +16,7 @@ import qualified Utility.Matcher
import qualified Remote
import qualified Backend
import Annex.Content
+import Logs.Trust
type Limit = Utility.Matcher.Token (FilePath -> Annex Bool)
@@ -83,16 +84,21 @@ addIn name = addLimit $ check $ if name == "." then inAnnex else inremote
{- Adds a limit to skip files not believed to have the specified number
- of copies. -}
addCopies :: String -> Annex ()
-addCopies num =
- case readish num :: Maybe Int of
- Nothing -> error "bad number for --copies"
- Just n -> addLimit $ check n
- where
+addCopies trust_num = addLimit . check $ readnum num
+ where (num, mayCheckTrust) =
+ case split ":" trust_num of
+ [trust, num'] -> (num', checkTrust (readtrust trust))
+ [num'] -> (num', const (return True))
+ _ -> bad
+ readnum = maybe bad id . readish
+ readtrust = maybe bad id . readTrust
check n = Backend.lookupFile >=> handle n
handle _ Nothing = return False
handle n (Just (key, _)) = do
- us <- Remote.keyLocations key
+ us <- filterM mayCheckTrust =<< Remote.keyLocations key
return $ length us >= n
+ checkTrust t u = (== t) <$> lookupTrust u -- == or >=
+ bad = error "bad number or trust:number for --copies"
{- Adds a limit to skip files not using a specified key-value backend. -}
addInBackend :: String -> Annex ()