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'.
This commit is contained in:
parent
c9b3b8829d
commit
f0bcc77fb2
2 changed files with 26 additions and 11 deletions
18
Limit.hs
18
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 ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue