diff options
author | Joey Hess <joey@kitenet.net> | 2012-09-23 15:35:00 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-09-23 15:35:00 -0400 |
commit | 0732d4c8efcc383919b9016881125dd147886121 (patch) | |
tree | 92c5b7e8a783f53df5796595a6aa5abaebcb4e8b /Limit.hs | |
parent | 90eea19ea2bc96070fef376cb4d35df35a1c49e5 (diff) | |
parent | f0bcc77fb245c5fccadff728fd816471fd9993bf (diff) |
Merge remote-tracking branch 'npouillard/trustedcopies'
Diffstat (limited to 'Limit.hs')
-rw-r--r-- | Limit.hs | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -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 () |