finish wiring up groupwanted
This commit is contained in:
parent
3a9a1b9f63
commit
6a4dd42328
4 changed files with 41 additions and 29 deletions
|
@ -56,23 +56,24 @@ parsedToMatcher parsed = case partitionEithers parsed of
|
||||||
([], vs) -> Right $ generate vs
|
([], vs) -> Right $ generate vs
|
||||||
(es, _) -> Left $ unwords $ map ("Parse failure: " ++) es
|
(es, _) -> Left $ unwords $ map ("Parse failure: " ++) es
|
||||||
|
|
||||||
exprParser :: FileMatcher -> GroupMap -> M.Map UUID RemoteConfig -> Maybe UUID -> String -> [Either String (Token MatchFiles)]
|
exprParser :: FileMatcher -> FileMatcher -> GroupMap -> M.Map UUID RemoteConfig -> Maybe UUID -> String -> [Either String (Token MatchFiles)]
|
||||||
exprParser matchstandard groupmap configmap mu expr =
|
exprParser matchstandard matchgroupwanted groupmap configmap mu expr =
|
||||||
map parse $ tokenizeMatcher expr
|
map parse $ tokenizeMatcher expr
|
||||||
where
|
where
|
||||||
parse = parseToken
|
parse = parseToken
|
||||||
matchstandard
|
matchstandard
|
||||||
|
matchgroupwanted
|
||||||
(limitPresent mu)
|
(limitPresent mu)
|
||||||
(limitInDir preferreddir)
|
(limitInDir preferreddir)
|
||||||
groupmap
|
groupmap
|
||||||
preferreddir = fromMaybe "public" $
|
preferreddir = fromMaybe "public" $
|
||||||
M.lookup "preferreddir" =<< (`M.lookup` configmap) =<< mu
|
M.lookup "preferreddir" =<< (`M.lookup` configmap) =<< mu
|
||||||
|
|
||||||
parseToken :: FileMatcher -> MkLimit -> MkLimit -> GroupMap -> String -> Either String (Token MatchFiles)
|
parseToken :: FileMatcher -> FileMatcher -> MkLimit -> MkLimit -> GroupMap -> String -> Either String (Token MatchFiles)
|
||||||
parseToken matchstandard checkpresent checkpreferreddir groupmap t
|
parseToken matchstandard matchgroupwanted checkpresent checkpreferreddir groupmap t
|
||||||
| t `elem` tokens = Right $ token t
|
| t `elem` tokens = Right $ token t
|
||||||
| t == "standard" = Right $ Operation $ \notpresent mi ->
|
| t == "standard" = call matchstandard
|
||||||
matchMrun matchstandard $ \a -> a notpresent mi
|
| t == "groupwanted" = call matchgroupwanted
|
||||||
| t == "present" = use checkpresent
|
| t == "present" = use checkpresent
|
||||||
| t == "inpreferreddir" = use checkpreferreddir
|
| t == "inpreferreddir" = use checkpreferreddir
|
||||||
| t == "unused" = Right $ Operation limitUnused
|
| t == "unused" = Right $ Operation limitUnused
|
||||||
|
@ -92,6 +93,8 @@ parseToken matchstandard checkpresent checkpreferreddir groupmap t
|
||||||
where
|
where
|
||||||
(k, v) = separate (== '=') t
|
(k, v) = separate (== '=') t
|
||||||
use a = Operation <$> a v
|
use a = Operation <$> a v
|
||||||
|
call sub = Right $ Operation $ \notpresent mi ->
|
||||||
|
matchMrun sub $ \a -> a notpresent mi
|
||||||
|
|
||||||
{- This is really dumb tokenization; there's no support for quoted values.
|
{- This is really dumb tokenization; there's no support for quoted values.
|
||||||
- Open and close parens are always treated as standalone tokens;
|
- Open and close parens are always treated as standalone tokens;
|
||||||
|
@ -112,5 +115,5 @@ largeFilesMatcher = go =<< annexLargeFiles <$> Annex.getGitConfig
|
||||||
rc <- readRemoteLog
|
rc <- readRemoteLog
|
||||||
u <- getUUID
|
u <- getUUID
|
||||||
either badexpr return $
|
either badexpr return $
|
||||||
parsedToMatcher $ exprParser matchAll gm rc (Just u) expr
|
parsedToMatcher $ exprParser matchAll matchAll gm rc (Just u) expr
|
||||||
badexpr e = error $ "bad annex.largefiles configuration: " ++ e
|
badexpr e = error $ "bad annex.largefiles configuration: " ++ e
|
||||||
|
|
|
@ -158,7 +158,7 @@ genCfg cfg descs = unlines $ intercalate [""]
|
||||||
where
|
where
|
||||||
gline g = com $ unwords
|
gline g = com $ unwords
|
||||||
[ "standard"
|
[ "standard"
|
||||||
, fromStandardGroup g, "=", preferredContent g
|
, fromStandardGroup g, "=", standardPreferredContent g
|
||||||
]
|
]
|
||||||
|
|
||||||
schedule = settings cfg descs cfgScheduleMap
|
schedule = settings cfg descs cfgScheduleMap
|
||||||
|
|
|
@ -58,8 +58,9 @@ preferredContentMapLoad :: Annex Annex.PreferredContentMap
|
||||||
preferredContentMapLoad = do
|
preferredContentMapLoad = do
|
||||||
groupmap <- groupMap
|
groupmap <- groupMap
|
||||||
configmap <- readRemoteLog
|
configmap <- readRemoteLog
|
||||||
|
groupwantedmap <- groupPreferredContentMapRaw
|
||||||
m <- simpleMap
|
m <- simpleMap
|
||||||
. parseLogWithUUID ((Just .) . makeMatcher groupmap configmap)
|
. parseLogWithUUID ((Just .) . makeMatcher groupmap configmap groupwantedmap)
|
||||||
<$> Annex.Branch.get preferredContentLog
|
<$> Annex.Branch.get preferredContentLog
|
||||||
Annex.changeState $ \s -> s { Annex.preferredcontentmap = Just m }
|
Annex.changeState $ \s -> s { Annex.preferredcontentmap = Just m }
|
||||||
return m
|
return m
|
||||||
|
@ -68,18 +69,26 @@ preferredContentMapLoad = do
|
||||||
- because the configuration is shared among repositories and newer
|
- because the configuration is shared among repositories and newer
|
||||||
- versions of git-annex may add new features. Instead, parse errors
|
- versions of git-annex may add new features. Instead, parse errors
|
||||||
- result in a Matcher that will always succeed. -}
|
- result in a Matcher that will always succeed. -}
|
||||||
makeMatcher :: GroupMap -> M.Map UUID RemoteConfig -> UUID -> PreferredContentExpression -> FileMatcher
|
makeMatcher :: GroupMap -> M.Map UUID RemoteConfig -> M.Map Group PreferredContentExpression -> UUID -> PreferredContentExpression -> FileMatcher
|
||||||
makeMatcher groupmap configmap u = go True
|
makeMatcher groupmap configmap groupwantedmap u = go True True
|
||||||
where
|
where
|
||||||
go expandstandard expr
|
go expandstandard expandgroupwanted expr
|
||||||
| null (lefts tokens) = Utility.Matcher.generate $ rights tokens
|
| null (lefts tokens) = Utility.Matcher.generate $ rights tokens
|
||||||
| otherwise = matchAll
|
| otherwise = matchAll
|
||||||
where
|
where
|
||||||
tokens = exprParser matchstandard groupmap configmap (Just u) expr
|
tokens = exprParser matchstandard matchgroupwanted groupmap configmap (Just u) expr
|
||||||
matchstandard
|
matchstandard
|
||||||
| expandstandard = maybe matchAll (go False . preferredContent) $
|
| expandstandard = maybe matchAll (go False False)
|
||||||
getStandardGroup =<< u `M.lookup` groupsByUUID groupmap
|
(standardPreferredContent <$> getStandardGroup mygroups)
|
||||||
| otherwise = matchAll
|
| otherwise = matchAll
|
||||||
|
matchgroupwanted
|
||||||
|
| expandgroupwanted = maybe matchAll (go True False)
|
||||||
|
(groupwanted mygroups)
|
||||||
|
| otherwise = matchAll
|
||||||
|
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
|
||||||
|
|
||||||
{- Checks if an expression can be parsed, if not returns Just error -}
|
{- Checks if an expression can be parsed, if not returns Just error -}
|
||||||
checkPreferredContentExpression :: PreferredContentExpression -> Maybe String
|
checkPreferredContentExpression :: PreferredContentExpression -> Maybe String
|
||||||
|
@ -87,7 +96,7 @@ checkPreferredContentExpression expr = case parsedToMatcher tokens of
|
||||||
Left e -> Just e
|
Left e -> Just e
|
||||||
Right _ -> Nothing
|
Right _ -> Nothing
|
||||||
where
|
where
|
||||||
tokens = exprParser matchAll emptyGroupMap M.empty Nothing expr
|
tokens = exprParser matchAll matchAll emptyGroupMap M.empty Nothing expr
|
||||||
|
|
||||||
{- Puts a UUID in a standard group, and sets its preferred content to use
|
{- Puts a UUID in a standard group, and sets its preferred content to use
|
||||||
- the standard expression for that group, unless something is already set. -}
|
- the standard expression for that group, unless something is already set. -}
|
||||||
|
|
|
@ -78,21 +78,21 @@ specialRemoteOnly PublicGroup = True
|
||||||
specialRemoteOnly _ = False
|
specialRemoteOnly _ = False
|
||||||
|
|
||||||
{- See doc/preferred_content.mdwn for explanations of these expressions. -}
|
{- See doc/preferred_content.mdwn for explanations of these expressions. -}
|
||||||
preferredContent :: StandardGroup -> PreferredContentExpression
|
standardPreferredContent :: StandardGroup -> PreferredContentExpression
|
||||||
preferredContent ClientGroup = lastResort $
|
standardPreferredContent ClientGroup = lastResort $
|
||||||
"((exclude=*/archive/* and exclude=archive/*) or (" ++ notArchived ++ ")) and not unused"
|
"((exclude=*/archive/* and exclude=archive/*) or (" ++ notArchived ++ ")) and not unused"
|
||||||
preferredContent TransferGroup = lastResort $
|
standardPreferredContent TransferGroup = lastResort $
|
||||||
"not (inallgroup=client and copies=client:2) and (" ++ preferredContent ClientGroup ++ ")"
|
"not (inallgroup=client and copies=client:2) and (" ++ standardPreferredContent ClientGroup ++ ")"
|
||||||
preferredContent BackupGroup = "include=* or unused"
|
standardPreferredContent BackupGroup = "include=* or unused"
|
||||||
preferredContent IncrementalBackupGroup = lastResort
|
standardPreferredContent IncrementalBackupGroup = lastResort
|
||||||
"(include=* or unused) and (not copies=incrementalbackup:1)"
|
"(include=* or unused) and (not copies=incrementalbackup:1)"
|
||||||
preferredContent SmallArchiveGroup = lastResort $
|
standardPreferredContent SmallArchiveGroup = lastResort $
|
||||||
"(include=*/archive/* or include=archive/*) and (" ++ preferredContent FullArchiveGroup ++ ")"
|
"(include=*/archive/* or include=archive/*) and (" ++ standardPreferredContent FullArchiveGroup ++ ")"
|
||||||
preferredContent FullArchiveGroup = lastResort notArchived
|
standardPreferredContent FullArchiveGroup = lastResort notArchived
|
||||||
preferredContent SourceGroup = "not (copies=1)"
|
standardPreferredContent SourceGroup = "not (copies=1)"
|
||||||
preferredContent ManualGroup = "present and (" ++ preferredContent ClientGroup ++ ")"
|
standardPreferredContent ManualGroup = "present and (" ++ standardPreferredContent ClientGroup ++ ")"
|
||||||
preferredContent PublicGroup = "inpreferreddir"
|
standardPreferredContent PublicGroup = "inpreferreddir"
|
||||||
preferredContent UnwantedGroup = "exclude=*"
|
standardPreferredContent UnwantedGroup = "exclude=*"
|
||||||
|
|
||||||
notArchived :: String
|
notArchived :: String
|
||||||
notArchived = "not (copies=archive:1 or copies=smallarchive:1)"
|
notArchived = "not (copies=archive:1 or copies=smallarchive:1)"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue