aboutsummaryrefslogtreecommitdiff
path: root/Limit.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-19 16:09:21 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-19 16:09:21 -0400
commit5237b17193befdac87dfbeac9391e5ccad3049bb (patch)
treea107b4120c993103a0d37668ec9e6c9f3b28041e /Limit.hs
parent5f835c769eb673b28d2d0211adfd6cbdf420b4bc (diff)
Replace "in=" with "present" in preferred content expressions
in= was problimatic in two ways. First, it referred to a remote by name, but preferred content expressions can be evaluated elsewhere, where that remote doesn't exist, or a different remote has the same name. This name lookup code could error out at runtime. Secondly, in= seemed pretty useless. in=here did not cause content to be gotten, but it did let present content be dropped. present is more useful, although "not present" is unstable and should be avoided.
Diffstat (limited to 'Limit.hs')
-rw-r--r--Limit.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/Limit.hs b/Limit.hs
index cdaadfe2d..ae77d8a5a 100644
--- a/Limit.hs
+++ b/Limit.hs
@@ -113,6 +113,20 @@ limitIn name = Right $ \notpresent -> check $
then return False
else inAnnex key
+{- Limit to content that is currently present on a uuid. -}
+limitPresent :: Maybe UUID -> MkLimit
+limitPresent u name = Right $ const $ check $ \key -> do
+ hereu <- getUUID
+ if u == Just hereu || u == Nothing
+ then inAnnex key
+ else do
+ us <- Remote.keyLocations key
+ return $ maybe False (`elem` us) u
+ where
+ check a = lookupFile >=> handle a
+ handle _ Nothing = return False
+ handle a (Just (key, _)) = a key
+
{- Adds a limit to skip files not believed to have the specified number
- of copies. -}
addCopies :: String -> Annex ()