support standard and groupwanted in keyless mode
Only when the preferred content expression includes them will a parse failure due to them needing keys result in the preferred content expression not parsing in keyless mode.
This commit is contained in:
parent
5266da2cdd
commit
354c0eb57f
3 changed files with 26 additions and 22 deletions
|
@ -122,8 +122,8 @@ commonKeyedTokens =
|
||||||
]
|
]
|
||||||
|
|
||||||
data PreferredContentData = PCD
|
data PreferredContentData = PCD
|
||||||
{ matchStandard :: FileMatcher Annex
|
{ matchStandard :: Either String (FileMatcher Annex)
|
||||||
, matchGroupWanted :: FileMatcher Annex
|
, matchGroupWanted :: Either String (FileMatcher Annex)
|
||||||
, getGroupMap :: Annex GroupMap
|
, getGroupMap :: Annex GroupMap
|
||||||
, configMap :: M.Map UUID RemoteConfig
|
, configMap :: M.Map UUID RemoteConfig
|
||||||
, repoUUID :: Maybe UUID
|
, repoUUID :: Maybe UUID
|
||||||
|
@ -137,7 +137,9 @@ data PreferredContentData = PCD
|
||||||
-- so the Key is not known.
|
-- so the Key is not known.
|
||||||
preferredContentKeylessTokens :: PreferredContentData -> [ParseToken (MatchFiles Annex)]
|
preferredContentKeylessTokens :: PreferredContentData -> [ParseToken (MatchFiles Annex)]
|
||||||
preferredContentKeylessTokens pcd =
|
preferredContentKeylessTokens pcd =
|
||||||
[ SimpleToken "inpreferreddir" (simply $ limitInDir preferreddir)
|
[ SimpleToken "standard" (call $ matchStandard pcd)
|
||||||
|
, SimpleToken "groupwanted" (call $ matchGroupWanted pcd)
|
||||||
|
, SimpleToken "inpreferreddir" (simply $ limitInDir preferreddir)
|
||||||
] ++ commonKeylessTokens
|
] ++ commonKeylessTokens
|
||||||
where
|
where
|
||||||
preferreddir = fromMaybe "public" $
|
preferreddir = fromMaybe "public" $
|
||||||
|
@ -145,9 +147,7 @@ preferredContentKeylessTokens pcd =
|
||||||
|
|
||||||
preferredContentKeyedTokens :: PreferredContentData -> [ParseToken (MatchFiles Annex)]
|
preferredContentKeyedTokens :: PreferredContentData -> [ParseToken (MatchFiles Annex)]
|
||||||
preferredContentKeyedTokens pcd =
|
preferredContentKeyedTokens pcd =
|
||||||
[ SimpleToken "standard" (call $ matchStandard pcd)
|
[ SimpleToken "present" (simply $ limitPresent $ repoUUID pcd)
|
||||||
, SimpleToken "groupwanted" (call $ matchGroupWanted pcd)
|
|
||||||
, SimpleToken "present" (simply $ limitPresent $ repoUUID pcd)
|
|
||||||
, SimpleToken "securehash" (simply limitSecureHash)
|
, SimpleToken "securehash" (simply limitSecureHash)
|
||||||
, ValueToken "copies" (usev limitCopies)
|
, ValueToken "copies" (usev limitCopies)
|
||||||
, ValueToken "lackingcopies" (usev $ limitLackingCopies False)
|
, ValueToken "lackingcopies" (usev $ limitLackingCopies False)
|
||||||
|
@ -215,6 +215,7 @@ simply = Right . Operation
|
||||||
usev :: MkLimit Annex -> String -> ParseResult (MatchFiles Annex)
|
usev :: MkLimit Annex -> String -> ParseResult (MatchFiles Annex)
|
||||||
usev a v = Operation <$> a v
|
usev a v = Operation <$> a v
|
||||||
|
|
||||||
call :: FileMatcher Annex -> ParseResult (MatchFiles Annex)
|
call :: Either String (FileMatcher Annex) -> ParseResult (MatchFiles Annex)
|
||||||
call sub = Right $ Operation $ \notpresent mi ->
|
call (Right sub) = Right $ Operation $ \notpresent mi ->
|
||||||
matchMrun sub $ \a -> a notpresent mi
|
matchMrun sub $ \a -> a notpresent mi
|
||||||
|
call (Left err) = Left err
|
||||||
|
|
|
@ -79,8 +79,8 @@ seek o = do
|
||||||
else do
|
else do
|
||||||
u <- getUUID
|
u <- getUUID
|
||||||
pure $ preferredContentParser $ preferredContentTokens $ PCD
|
pure $ preferredContentParser $ preferredContentTokens $ PCD
|
||||||
{ matchStandard = matchAll
|
{ matchStandard = Right matchAll
|
||||||
, matchGroupWanted = matchAll
|
, matchGroupWanted = Right matchAll
|
||||||
, getGroupMap = groupMap
|
, getGroupMap = groupMap
|
||||||
, configMap = M.empty
|
, configMap = M.empty
|
||||||
, repoUUID = Just u
|
, repoUUID = Just u
|
||||||
|
|
|
@ -73,9 +73,12 @@ preferredRequiredMapsLoad :: (PreferredContentData -> [ParseToken (MatchFiles An
|
||||||
preferredRequiredMapsLoad mktokens = do
|
preferredRequiredMapsLoad mktokens = do
|
||||||
groupmap <- groupMap
|
groupmap <- groupMap
|
||||||
configmap <- readRemoteLog
|
configmap <- readRemoteLog
|
||||||
let genmap l gm = simpleMap
|
let genmap l gm =
|
||||||
. parseLogOldWithUUID (\u -> makeMatcher groupmap configmap gm u mktokens . decodeBS <$> A.takeByteString)
|
let mk u = fromRight (unknownMatcher u) .
|
||||||
<$> Annex.Branch.get l
|
makeMatcher groupmap configmap gm u mktokens
|
||||||
|
in simpleMap
|
||||||
|
. parseLogOldWithUUID (\u -> mk u . decodeBS <$> A.takeByteString)
|
||||||
|
<$> Annex.Branch.get l
|
||||||
pc <- genmap preferredContentLog =<< groupPreferredContentMapRaw
|
pc <- genmap preferredContentLog =<< groupPreferredContentMapRaw
|
||||||
rc <- genmap requiredContentLog M.empty
|
rc <- genmap requiredContentLog M.empty
|
||||||
-- Required content is implicitly also preferred content, so
|
-- Required content is implicitly also preferred content, so
|
||||||
|
@ -97,12 +100,12 @@ makeMatcher
|
||||||
-> UUID
|
-> UUID
|
||||||
-> (PreferredContentData -> [ParseToken (MatchFiles Annex)])
|
-> (PreferredContentData -> [ParseToken (MatchFiles Annex)])
|
||||||
-> PreferredContentExpression
|
-> PreferredContentExpression
|
||||||
-> FileMatcher Annex
|
-> Either String (FileMatcher Annex)
|
||||||
makeMatcher groupmap configmap groupwantedmap u mktokens = go True True
|
makeMatcher groupmap configmap groupwantedmap u mktokens = go True True
|
||||||
where
|
where
|
||||||
go expandstandard expandgroupwanted expr
|
go expandstandard expandgroupwanted expr
|
||||||
| null (lefts tokens) = generate $ rights tokens
|
| null (lefts tokens) = Right $ generate $ rights tokens
|
||||||
| otherwise = unknownMatcher u
|
| otherwise = Left (unwords (lefts tokens))
|
||||||
where
|
where
|
||||||
tokens = preferredContentParser (mktokens pcd) expr
|
tokens = preferredContentParser (mktokens pcd) expr
|
||||||
pcd = PCD
|
pcd = PCD
|
||||||
|
@ -113,13 +116,13 @@ makeMatcher groupmap configmap groupwantedmap u mktokens = go True True
|
||||||
, repoUUID = Just u
|
, repoUUID = Just u
|
||||||
}
|
}
|
||||||
matchstandard
|
matchstandard
|
||||||
| expandstandard = maybe (unknownMatcher u) (go False False)
|
| expandstandard = maybe (Right $ unknownMatcher u) (go False False)
|
||||||
(standardPreferredContent <$> getStandardGroup mygroups)
|
(standardPreferredContent <$> getStandardGroup mygroups)
|
||||||
| otherwise = unknownMatcher u
|
| otherwise = Right $ unknownMatcher u
|
||||||
matchgroupwanted
|
matchgroupwanted
|
||||||
| expandgroupwanted = maybe (unknownMatcher u) (go True False)
|
| expandgroupwanted = maybe (Right $ unknownMatcher u) (go True False)
|
||||||
(groupwanted mygroups)
|
(groupwanted mygroups)
|
||||||
| otherwise = unknownMatcher u
|
| otherwise = Right $ unknownMatcher u
|
||||||
mygroups = fromMaybe S.empty (u `M.lookup` groupsByUUID groupmap)
|
mygroups = fromMaybe S.empty (u `M.lookup` groupsByUUID groupmap)
|
||||||
groupwanted s = case M.elems $ M.filterWithKey (\k _ -> S.member k s) groupwantedmap of
|
groupwanted s = case M.elems $ M.filterWithKey (\k _ -> S.member k s) groupwantedmap of
|
||||||
[pc] -> Just pc
|
[pc] -> Just pc
|
||||||
|
@ -144,8 +147,8 @@ checkPreferredContentExpression expr = case parsedToMatcher tokens of
|
||||||
where
|
where
|
||||||
tokens = preferredContentParser (preferredContentTokens pcd) expr
|
tokens = preferredContentParser (preferredContentTokens pcd) expr
|
||||||
pcd = PCD
|
pcd = PCD
|
||||||
{ matchStandard = matchAll
|
{ matchStandard = Right matchAll
|
||||||
, matchGroupWanted = matchAll
|
, matchGroupWanted = Right matchAll
|
||||||
, getGroupMap = pure emptyGroupMap
|
, getGroupMap = pure emptyGroupMap
|
||||||
, configMap = M.empty
|
, configMap = M.empty
|
||||||
, repoUUID = Nothing
|
, repoUUID = Nothing
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue