add AssumeNotPresent parameter to limits

Solves the issue with preferred content expressions and dropping that
I mentioned yesterday. My solution was to add a parameter to specify a set
of repositories where content should be assumed not to be present. When
deciding whether to drop, it can put the current repository in, and then
if the expression fails to match, the content can be dropped.

Using yesterday's example "(not copies=trusted:2) and (not in=usbdrive)",
when the local repo is one of the 2 trusted copies, the drop check will
see only 1 trusted copy, so the expression matches, and so the content will
not be dropped.
This commit is contained in:
Joey Hess 2012-10-05 16:52:44 -04:00
parent 51f41bad63
commit 7bb4d507ba
3 changed files with 35 additions and 21 deletions

View file

@ -20,7 +20,7 @@ import Common.Annex
import qualified Annex.Branch
import qualified Annex
import Logs.UUIDBased
import Limit (limitInclude, limitExclude, limitIn, limitCopies, limitInBackend)
import Limit (MatchFiles, limitInclude, limitExclude, limitIn, limitCopies, limitInBackend)
import qualified Utility.Matcher
{- Filename of preferred-content.log. -}
@ -56,7 +56,7 @@ preferredContentMapRaw = simpleMap . parseLog Just
- because the configuration is shared amoung repositories and newer
- versions of git-annex may add new features. Instead, parse errors
- result in a Matcher that will always succeed. -}
makeMatcher :: String -> Utility.Matcher.Matcher (FilePath -> Annex Bool)
makeMatcher :: String -> Utility.Matcher.Matcher MatchFiles
makeMatcher s
| null (lefts tokens) = Utility.Matcher.generate $ rights tokens
| otherwise = Utility.Matcher.generate []
@ -69,7 +69,7 @@ checkPreferredContentExpression s = case lefts $ map parseToken $ tokenizeMatche
[] -> Nothing
l -> Just $ unwords $ map ("Parse failure: " ++) l
parseToken :: String -> Either String (Utility.Matcher.Token (FilePath -> Annex Bool))
parseToken :: String -> Either String (Utility.Matcher.Token MatchFiles)
parseToken t
| any (== t) Utility.Matcher.tokens = Right $ Utility.Matcher.token t
| otherwise = maybe (Left $ "near " ++ show t) use $ M.lookup k m