summaryrefslogtreecommitdiff
path: root/Command.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-07-10 11:53:45 -0600
committerGravatar Joey Hess <joey@kitenet.net>2012-07-10 11:53:45 -0600
commitaa558f0b00ef012f6c7532d8451de3fb1ed1eb9b (patch)
tree5a296752b628ce7ae926fcd3756a48eccf3ce363 /Command.hs
parent619297e1a7ba89f50fa5be9d7dfdfe5a9510129a (diff)
copy, drop: Avoid checking numcopies attribute unnecessarily
Diffstat (limited to 'Command.hs')
-rw-r--r--Command.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/Command.hs b/Command.hs
index 0dff0c862..cbffd39fa 100644
--- a/Command.hs
+++ b/Command.hs
@@ -21,6 +21,7 @@ module Command (
isBareRepo,
numCopies,
autoCopies,
+ autoCopiesWith,
module ReExported
) where
@@ -112,8 +113,18 @@ numCopies file = readish <$> checkAttr "annex.numcopies" file
- In auto mode, first checks that the number of known
- copies of the key is > or < than the numcopies setting, before running
- the action. -}
-autoCopies :: FilePath -> Key -> (Int -> Int -> Bool) -> (Maybe Int -> CommandStart) -> CommandStart
-autoCopies file key vs a = do
+autoCopies :: FilePath -> Key -> (Int -> Int -> Bool) -> CommandStart -> CommandStart
+autoCopies file key vs a = Annex.getState Annex.auto >>= go
+ where
+ go False = a
+ go True = do
+ numcopiesattr <- numCopies file
+ needed <- getNumCopies numcopiesattr
+ (_, have) <- trustPartition UnTrusted =<< Remote.keyLocations key
+ if length have `vs` needed then a else stop
+
+autoCopiesWith :: FilePath -> Key -> (Int -> Int -> Bool) -> (Maybe Int -> CommandStart) -> CommandStart
+autoCopiesWith file key vs a = do
numcopiesattr <- numCopies file
Annex.getState Annex.auto >>= auto numcopiesattr
where