simplify
This commit is contained in:
parent
5d9c7a1164
commit
cdf5977053
3 changed files with 19 additions and 22 deletions
|
@ -71,33 +71,33 @@ exprParser matchstandard matchgroupwanted getgroupmap configmap mu expr =
|
|||
preferreddir = fromMaybe "public" $
|
||||
M.lookup "preferreddir" =<< (`M.lookup` configmap) =<< mu
|
||||
|
||||
parseToken :: FileMatcher Annex -> FileMatcher Annex -> MkLimit Annex -> MkLimit Annex -> Annex GroupMap -> String -> Either String (Token (MatchFiles Annex))
|
||||
parseToken :: FileMatcher Annex -> FileMatcher Annex -> MatchFiles Annex -> MatchFiles Annex -> Annex GroupMap -> String -> Either String (Token (MatchFiles Annex))
|
||||
parseToken matchstandard matchgroupwanted checkpresent checkpreferreddir getgroupmap t
|
||||
| t `elem` tokens = Right $ token t
|
||||
| otherwise = case t of
|
||||
"standard" -> call matchstandard
|
||||
"groupwanted" -> call matchgroupwanted
|
||||
"present" -> use checkpresent
|
||||
"inpreferreddir" -> use checkpreferreddir
|
||||
"present" -> simply checkpresent
|
||||
"inpreferreddir" -> simply checkpreferreddir
|
||||
"unused" -> simply limitUnused
|
||||
"anything" -> simply limitAnything
|
||||
"nothing" -> simply limitNothing
|
||||
_ -> case k of
|
||||
"include" -> use limitInclude
|
||||
"exclude" -> use limitExclude
|
||||
"copies" -> use limitCopies
|
||||
"lackingcopies" -> use $ limitLackingCopies False
|
||||
"approxlackingcopies" -> use $ limitLackingCopies True
|
||||
"inbackend" -> use limitInBackend
|
||||
"largerthan" -> use $ limitSize (>)
|
||||
"smallerthan" -> use $ limitSize (<)
|
||||
"metadata" -> use limitMetaData
|
||||
"inallgroup" -> use $ limitInAllGroup getgroupmap
|
||||
"include" -> usev limitInclude
|
||||
"exclude" -> usev limitExclude
|
||||
"copies" -> usev limitCopies
|
||||
"lackingcopies" -> usev $ limitLackingCopies False
|
||||
"approxlackingcopies" -> usev $ limitLackingCopies True
|
||||
"inbackend" -> usev limitInBackend
|
||||
"largerthan" -> usev $ limitSize (>)
|
||||
"smallerthan" -> usev $ limitSize (<)
|
||||
"metadata" -> usev limitMetaData
|
||||
"inallgroup" -> usev $ limitInAllGroup getgroupmap
|
||||
_ -> Left $ "near " ++ show t
|
||||
where
|
||||
(k, v) = separate (== '=') t
|
||||
simply = Right . Operation
|
||||
use a = Operation <$> a v
|
||||
usev a = Operation <$> a v
|
||||
call sub = Right $ Operation $ \notpresent mi ->
|
||||
matchMrun sub $ \a -> a notpresent mi
|
||||
|
||||
|
|
11
Limit.hs
11
Limit.hs
|
@ -118,11 +118,8 @@ addIn s = addLimit =<< mk
|
|||
else inAnnex key
|
||||
|
||||
{- Limit to content that is currently present on a uuid. -}
|
||||
limitPresent :: Maybe UUID -> MkLimit Annex
|
||||
limitPresent u _ = Right $ matchPresent u
|
||||
|
||||
matchPresent :: Maybe UUID -> MatchFiles Annex
|
||||
matchPresent u _ = checkKey $ \key -> do
|
||||
limitPresent :: Maybe UUID -> MatchFiles Annex
|
||||
limitPresent u _ = checkKey $ \key -> do
|
||||
hereu <- getUUID
|
||||
if u == Just hereu || isNothing u
|
||||
then inAnnex key
|
||||
|
@ -131,8 +128,8 @@ matchPresent u _ = checkKey $ \key -> do
|
|||
return $ maybe False (`elem` us) u
|
||||
|
||||
{- Limit to content that is in a directory, anywhere in the repository tree -}
|
||||
limitInDir :: FilePath -> MkLimit Annex
|
||||
limitInDir dir = const $ Right $ const go
|
||||
limitInDir :: FilePath -> MatchFiles Annex
|
||||
limitInDir dir = const go
|
||||
where
|
||||
go (MatchingFile fi) = checkf $ matchFile fi
|
||||
go (MatchingKey _) = return False
|
||||
|
|
|
@ -125,7 +125,7 @@ makeMatcher groupmap configmap groupwantedmap u = go True True
|
|||
unknownMatcher :: UUID -> FileMatcher Annex
|
||||
unknownMatcher u = generate [present]
|
||||
where
|
||||
present = Operation $ matchPresent (Just u)
|
||||
present = Operation $ limitPresent (Just u)
|
||||
|
||||
{- Checks if an expression can be parsed, if not returns Just error -}
|
||||
checkPreferredContentExpression :: PreferredContentExpression -> Maybe String
|
||||
|
|
Loading…
Add table
Reference in a new issue