aboutsummaryrefslogtreecommitdiff
path: root/Limit.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-09-18 20:23:08 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-09-18 20:23:08 -0400
commit9da23dff78d80158ba01a271ac2a32830fd9bccc (patch)
tree007f7fd05eb844d9e8fd04a172adbd6436e31544 /Limit.hs
parent1fc3ee24232059ae05ab18ed10bf151f86847ac1 (diff)
--copies=N can be used to make git-annex only operate on files with the specified number of copies.
(And --not --copies=N for the inverse.)
Diffstat (limited to 'Limit.hs')
-rw-r--r--Limit.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/Limit.hs b/Limit.hs
index 13df5f6c2..4aeb8bafb 100644
--- a/Limit.hs
+++ b/Limit.hs
@@ -17,6 +17,7 @@ import qualified Utility.Matcher
import qualified Remote
import qualified Backend
import LocationLog
+import Utility
type Limit = Utility.Matcher.Token (FilePath -> Annex Bool)
@@ -73,3 +74,17 @@ addIn name = do
handle u (Just (key, _)) = do
us <- keyLocations key
return $ u `elem` us
+
+{- Adds a limit to skip files not believed to have the specified number
+ - of copies. -}
+addCopies :: String -> Annex ()
+addCopies num = do
+ case readMaybe num :: Maybe Int of
+ Nothing -> error "bad number for --copies"
+ Just n -> addlimit $ check n
+ where
+ check n f = Backend.lookupFile f >>= handle n
+ handle _ Nothing = return False
+ handle n (Just (key, _)) = do
+ us <- keyLocations key
+ return $ length us >= n