diff options
author | Joey Hess <joey@kitenet.net> | 2014-03-20 00:10:12 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-03-20 00:10:12 -0400 |
commit | e8afcf6e6dcda746ed365c1b64de3b2171418830 (patch) | |
tree | e220837a41ad25eb4f722d7ae8dcabc571d26be2 /Logs | |
parent | 1018c549a7e0c7442239533d0c62c83a0978f7d6 (diff) |
Improve behavior when unable to parse a preferred content expression (thanks, ion).
Fall back to "present" as the preferred conent expression, which will
not result in any content movement.
Diffstat (limited to 'Logs')
-rw-r--r-- | Logs/PreferredContent.hs | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/Logs/PreferredContent.hs b/Logs/PreferredContent.hs index a0bb4ffda..5580c062d 100644 --- a/Logs/PreferredContent.hs +++ b/Logs/PreferredContent.hs @@ -37,6 +37,7 @@ import Types.Remote (RemoteConfig) import Logs.Group import Logs.Remote import Types.StandardGroups +import Limit {- Checks if a file is preferred content for the specified repository - (or the current repository if none is specified). -} @@ -67,29 +68,45 @@ preferredContentMapLoad = do {- This intentionally never fails, even on unparsable expressions, - because the configuration is shared among repositories and newer - - versions of git-annex may add new features. Instead, parse errors - - result in a Matcher that will always succeed. -} -makeMatcher :: GroupMap -> M.Map UUID RemoteConfig -> M.Map Group PreferredContentExpression -> UUID -> PreferredContentExpression -> FileMatcher + - versions of git-annex may add new features. -} +makeMatcher + :: GroupMap + -> M.Map UUID RemoteConfig + -> M.Map Group PreferredContentExpression + -> UUID + -> PreferredContentExpression + -> FileMatcher makeMatcher groupmap configmap groupwantedmap u = go True True where go expandstandard expandgroupwanted expr | null (lefts tokens) = Utility.Matcher.generate $ rights tokens - | otherwise = matchAll + | otherwise = unknownMatcher u where tokens = exprParser matchstandard matchgroupwanted groupmap configmap (Just u) expr matchstandard - | expandstandard = maybe matchAll (go False False) + | expandstandard = maybe (unknownMatcher u) (go False False) (standardPreferredContent <$> getStandardGroup mygroups) - | otherwise = matchAll + | otherwise = unknownMatcher u matchgroupwanted - | expandgroupwanted = maybe matchAll (go True False) + | expandgroupwanted = maybe (unknownMatcher u) (go True False) (groupwanted mygroups) - | otherwise = matchAll + | otherwise = 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 _ -> Nothing +{- When a preferred content expression cannot be parsed, but is already + - in the log (eg, put there by a newer version of git-annex), + - the fallback behavior is to match only files that are currently present. + - + - This avoid unwanted/expensive changes to the content, until the problem + - is resolved. -} +unknownMatcher :: UUID -> FileMatcher +unknownMatcher u = Utility.Matcher.generate [present] + where + present = Utility.Matcher.Operation $ matchPresent (Just u) + {- Checks if an expression can be parsed, if not returns Just error -} checkPreferredContentExpression :: PreferredContentExpression -> Maybe String checkPreferredContentExpression expr = case parsedToMatcher tokens of |