fix preferred content check for 1 semitrusted or better copy
authorJoey Hess <joey@kitenet.net>
Wed, 3 Apr 2013 03:40:13 +0000 (23:40 -0400)
committerJoey Hess <joey@kitenet.net>
Wed, 3 Apr 2013 03:40:13 +0000 (23:40 -0400)
Let's make semitrusted+:1 mean that, since it cannot be expressed easily
with the current syntax (could use (semitrusted:1 or trusted:1), but that
does not scale to higher values than 2 copy, and also fails if I add more
trust levels).

Thanks to Andy for spotting this bug by just reading my blog.

Limit.hs
Types/StandardGroups.hs
doc/git-annex.mdwn
doc/preferred_content.mdwn

index 98227144d292ec2e8cbcca58d8a2009b67ac7e47..1d8646bb17e9386ffc0ec76c99ba14b2fb9c5556 100644 (file)
--- a/Limit.hs
+++ b/Limit.hs
@@ -145,8 +145,8 @@ addCopies = addLimit . limitCopies
 
 limitCopies :: MkLimit
 limitCopies want = case split ":" want of
-       [v, n] -> case readTrustLevel v of
-               Just trust -> go n $ checktrust trust
+       [v, n] -> case parsetrustspec v of
+               Just pred -> go n $ checktrust pred
                Nothing -> go n $ checkgroup v
        [n] -> go n $ const $ return True
        _ -> Left "bad value for copies"
@@ -160,8 +160,11 @@ limitCopies want = case split ":" want of
                us <- filter (`S.notMember` notpresent)
                        <$> (filterM good =<< Remote.keyLocations key)
                return $ length us >= n
-       checktrust t u = (== t) <$> lookupTrust u
+       checktrust pred u = pred <$> lookupTrust u
        checkgroup g u = S.member g <$> lookupGroups u
+       parsetrustspec s
+               | "+" `isSuffixOf` s = (>=) <$> readTrustLevel (beginning s)
+               | otherwise = (==) <$> readTrustLevel s
 
 {- Adds a limit to skip files not believed to be present in all
  - repositories in the specified group. -}
index 2670ec2a430f56178aa387874c2593df3ceb6d72..2262c3bded0475f4e1437813626d4bf6b0e41794 100644 (file)
@@ -74,4 +74,4 @@ preferredContent UnwantedGroup = "exclude=*"
 {- Most repositories want any content that is only on untrusted
  - or dead repositories. -}
 lastResort :: String -> String
-lastResort s = "(" ++ s ++ ") or (not copies=semitrusted:1)"
+lastResort s = "(" ++ s ++ ") or (not copies=semitrusted+:1)"
index 2e8efa95dc2c797a24934934e9d5492851084504..2f4bb5cdb879c5cfdf5ade3f81c12854d7726e22 100644 (file)
@@ -688,6 +688,9 @@ file contents are present at either of two repositories.
   copies, on remotes with the specified trust level. For example,
   "--copies=trusted:2"
 
+  To match any trust level at or higher than a given level, use
+  'trustlevel+'. For example, "--copies=semitrusted+:2"
+
 * --copies=groupname:number
 
   Matches only files that git-annex believes have the specified number of
index f8f937e4aadf0dbe1445650dbe0ab56c07914730..f8fd29c9d3c1056a8f4feac849016656f6047a14 100644 (file)
@@ -88,7 +88,7 @@ any repository that can will back it up.)
 
 All content is preferred, unless it's in a "archive" directory.
 
-`(exclude=*/archive/* and exclude=archive/*) or (not copies=semitrusted:1)`
+`(exclude=*/archive/* and exclude=archive/*) or (not copies=semitrusted+:1)`
 
 ### transfer
 
@@ -100,7 +100,7 @@ USB drive used in a sneakernet.
 The preferred content expression for these causes them to get and retain
 data until all clients have a copy.
 
-`(not (inallgroup=client and copies=client:2) and exclude=*/archive/* and exclude=archive/*) or (not copies=semitrusted:1)`
+`(not (inallgroup=client and copies=client:2) and exclude=*/archive/* and exclude=archive/*) or (not copies=semitrusted+:1)`
 
 The "copies=client:2" part of the above handles the case where
 there is only one client repository. It makes a transfer repository
@@ -119,20 +119,20 @@ All content is preferred.
 Only prefers content that's not already backed up to another backup
 or incremental backup repository.
 
-`(include=* and (not copies=backup:1) and (not copies=incrementalbackup:1)) or (not copies=semitrusted:1)`
+`(include=* and (not copies=backup:1) and (not copies=incrementalbackup:1)) or (not copies=semitrusted+:1)`
 
 ### small archive
 
 Only prefers content that's located in an "archive" directory, and
 only if it's not already been archived somewhere else.
 
-`((include=*/archive/* or include=archive/*) and not (copies=archive:1 or copies=smallarchive:1)) or (not copies=semitrusted:1)`
+`((include=*/archive/* or include=archive/*) and not (copies=archive:1 or copies=smallarchive:1)) or (not copies=semitrusted+:1)`
 
 ### full archive
 
 All content is preferred, unless it's already been archived somewhere else.
 
-`(not (copies=archive:1 or copies=smallarchive:1)) or (not copies=semitrusted:1)`
+`(not (copies=archive:1 or copies=smallarchive:1)) or (not copies=semitrusted+:1)`
 
 Note that if you want to archive multiple copies (not a bad idea!),
 you should instead configure all your archive repositories with a
@@ -160,7 +160,7 @@ local copy of every file. Instead, you can manually run `git annex get`,
 Only content that is present is preferred. Content in "archive"
 directories is never preferred.
 
-`(present and exclude=*/archive/* and exclude=archive/*) or (not copies=semitrusted:1)`
+`(present and exclude=*/archive/* and exclude=archive/*) or (not copies=semitrusted+:1)`
 
 ### unwanted