summaryrefslogtreecommitdiff
path: root/Command.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Command.hs')
-rw-r--r--Command.hs19
1 files changed, 19 insertions, 0 deletions
diff --git a/Command.hs b/Command.hs
index 710f36ea3..9d85fbe9d 100644
--- a/Command.hs
+++ b/Command.hs
@@ -26,6 +26,9 @@ import qualified Git
import qualified Git.LsFiles as LsFiles
import Utility
import Types.Key
+import Trust
+import LocationLog
+import Config
{- A command runs in four stages.
-
@@ -276,3 +279,19 @@ preserveOrder orig new = collect orig new
-}
runPreserveOrder :: ([FilePath] -> IO [FilePath]) -> [FilePath] -> IO [FilePath]
runPreserveOrder a files = preserveOrder files <$> a files
+
+{- Used for commands that have an auto mode that checks the number of known
+ - copies of a key.
+ -
+ - 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 :: Key -> (Int -> Int -> Bool) -> Maybe Int -> CommandStart -> CommandStart
+autoCopies key vs numcopiesattr a = do
+ auto <- Annex.getState Annex.auto
+ if auto
+ then do
+ needed <- getNumCopies numcopiesattr
+ (_, have) <- trustPartition UnTrusted =<< keyLocations key
+ if length have `vs` needed then a else stop
+ else a