diff options
author | Joey Hess <joeyh@joeyh.name> | 2019-05-14 14:59:03 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2019-05-14 14:59:03 -0400 |
commit | 354c0eb57feee593ae037a829a2d4a6861a16e2c (patch) | |
tree | 99871160e504fed0719b63053680388d4a35bebe | |
parent | 5266da2cdd72ecaf5db4354d6ac35abf4f27f8a4 (diff) |
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.
-rw-r--r-- | Annex/FileMatcher.hs | 17 | ||||
-rw-r--r-- | Command/MatchExpression.hs | 4 | ||||
-rw-r--r-- | Logs/PreferredContent.hs | 27 |
3 files changed, 26 insertions, 22 deletions
diff --git a/Annex/FileMatcher.hs b/Annex/FileMatcher.hs index 4a9d2126f2..87cf49a244 100644 --- a/Annex/FileMatcher.hs +++ b/Annex/FileMatcher.hs @@ -122,8 +122,8 @@ commonKeyedTokens = ] data PreferredContentData = PCD - { matchStandard :: FileMatcher Annex - , matchGroupWanted :: FileMatcher Annex + { matchStandard :: Either String (FileMatcher Annex) + , matchGroupWanted :: Either String (FileMatcher Annex) , getGroupMap :: Annex GroupMap , configMap :: M.Map UUID RemoteConfig , repoUUID :: Maybe UUID @@ -137,7 +137,9 @@ data PreferredContentData = PCD -- so the Key is not known. preferredContentKeylessTokens :: PreferredContentData -> [ParseToken (MatchFiles Annex)] preferredContentKeylessTokens pcd = - [ SimpleToken "inpreferreddir" (simply $ limitInDir preferreddir) + [ SimpleToken "standard" (call $ matchStandard pcd) + , SimpleToken "groupwanted" (call $ matchGroupWanted pcd) + , SimpleToken "inpreferreddir" (simply $ limitInDir preferreddir) ] ++ commonKeylessTokens where preferreddir = fromMaybe "public" $ @@ -145,9 +147,7 @@ preferredContentKeylessTokens pcd = preferredContentKeyedTokens :: PreferredContentData -> [ParseToken (MatchFiles Annex)] preferredContentKeyedTokens pcd = - [ SimpleToken "standard" (call $ matchStandard pcd) - , SimpleToken "groupwanted" (call $ matchGroupWanted pcd) - , SimpleToken "present" (simply $ limitPresent $ repoUUID pcd) + [ SimpleToken "present" (simply $ limitPresent $ repoUUID pcd) , SimpleToken "securehash" (simply limitSecureHash) , ValueToken "copies" (usev limitCopies) , ValueToken "lackingcopies" (usev $ limitLackingCopies False) @@ -215,6 +215,7 @@ simply = Right . Operation usev :: MkLimit Annex -> String -> ParseResult (MatchFiles Annex) usev a v = Operation <$> a v -call :: FileMatcher Annex -> ParseResult (MatchFiles Annex) -call sub = Right $ Operation $ \notpresent mi -> +call :: Either String (FileMatcher Annex) -> ParseResult (MatchFiles Annex) +call (Right sub) = Right $ Operation $ \notpresent mi -> matchMrun sub $ \a -> a notpresent mi +call (Left err) = Left err diff --git a/Command/MatchExpression.hs b/Command/MatchExpression.hs index 024417bb2f..77ceb0662e 100644 --- a/Command/MatchExpression.hs +++ b/Command/MatchExpression.hs @@ -79,8 +79,8 @@ seek o = do else do u <- getUUID pure $ preferredContentParser $ preferredContentTokens $ PCD - { matchStandard = matchAll - , matchGroupWanted = matchAll + { matchStandard = Right matchAll + , matchGroupWanted = Right matchAll , getGroupMap = groupMap , configMap = M.empty , repoUUID = Just u diff --git a/Logs/PreferredContent.hs b/Logs/PreferredContent.hs index c36fb3ea73..16ffef1297 100644 --- a/Logs/PreferredContent.hs +++ b/Logs/PreferredContent.hs @@ -73,9 +73,12 @@ preferredRequiredMapsLoad :: (PreferredContentData -> [ParseToken (MatchFiles An preferredRequiredMapsLoad mktokens = do groupmap <- groupMap configmap <- readRemoteLog - let genmap l gm = simpleMap - . parseLogOldWithUUID (\u -> makeMatcher groupmap configmap gm u mktokens . decodeBS <$> A.takeByteString) - <$> Annex.Branch.get l + let genmap l gm = + let mk u = fromRight (unknownMatcher u) . + makeMatcher groupmap configmap gm u mktokens + in simpleMap + . parseLogOldWithUUID (\u -> mk u . decodeBS <$> A.takeByteString) + <$> Annex.Branch.get l pc <- genmap preferredContentLog =<< groupPreferredContentMapRaw rc <- genmap requiredContentLog M.empty -- Required content is implicitly also preferred content, so @@ -97,12 +100,12 @@ makeMatcher -> UUID -> (PreferredContentData -> [ParseToken (MatchFiles Annex)]) -> PreferredContentExpression - -> FileMatcher Annex + -> Either String (FileMatcher Annex) makeMatcher groupmap configmap groupwantedmap u mktokens = go True True where go expandstandard expandgroupwanted expr - | null (lefts tokens) = generate $ rights tokens - | otherwise = unknownMatcher u + | null (lefts tokens) = Right $ generate $ rights tokens + | otherwise = Left (unwords (lefts tokens)) where tokens = preferredContentParser (mktokens pcd) expr pcd = PCD @@ -113,13 +116,13 @@ makeMatcher groupmap configmap groupwantedmap u mktokens = go True True , repoUUID = Just u } matchstandard - | expandstandard = maybe (unknownMatcher u) (go False False) + | expandstandard = maybe (Right $ unknownMatcher u) (go False False) (standardPreferredContent <$> getStandardGroup mygroups) - | otherwise = unknownMatcher u + | otherwise = Right $ unknownMatcher u matchgroupwanted - | expandgroupwanted = maybe (unknownMatcher u) (go True False) + | expandgroupwanted = maybe (Right $ unknownMatcher u) (go True False) (groupwanted mygroups) - | otherwise = unknownMatcher u + | otherwise = Right $ unknownMatcher u mygroups = fromMaybe S.empty (u `M.lookup` groupsByUUID groupmap) groupwanted s = case M.elems $ M.filterWithKey (\k _ -> S.member k s) groupwantedmap of [pc] -> Just pc @@ -144,8 +147,8 @@ checkPreferredContentExpression expr = case parsedToMatcher tokens of where tokens = preferredContentParser (preferredContentTokens pcd) expr pcd = PCD - { matchStandard = matchAll - , matchGroupWanted = matchAll + { matchStandard = Right matchAll + , matchGroupWanted = Right matchAll , getGroupMap = pure emptyGroupMap , configMap = M.empty , repoUUID = Nothing |