summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Command.hs15
-rw-r--r--Command/Copy.hs2
-rw-r--r--Command/Drop.hs2
-rw-r--r--Command/Get.hs2
4 files changed, 16 insertions, 5 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
diff --git a/Command/Copy.hs b/Command/Copy.hs
index a8ec22570..5d92eef2e 100644
--- a/Command/Copy.hs
+++ b/Command/Copy.hs
@@ -24,5 +24,5 @@ seek = [withField Command.Move.toOption Remote.byName $ \to ->
-- A copy is just a move that does not delete the source file.
-- However, --auto mode avoids unnecessary copies.
start :: Maybe Remote -> Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
-start to from file (key, backend) = autoCopies file key (<) $ \_numcopies ->
+start to from file (key, backend) = autoCopies file key (<) $
Command.Move.start to from False file (key, backend)
diff --git a/Command/Drop.hs b/Command/Drop.hs
index 28a52d626..ddf44ab82 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -30,7 +30,7 @@ seek = [withField fromOption Remote.byName $ \from ->
withFilesInGit $ whenAnnexed $ start from]
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
-start from file (key, _) = autoCopies file key (>) $ \numcopies ->
+start from file (key, _) = autoCopiesWith file key (>) $ \numcopies ->
case from of
Nothing -> startLocal file numcopies key
Just remote -> do
diff --git a/Command/Get.hs b/Command/Get.hs
index a5901ba66..95a7040bb 100644
--- a/Command/Get.hs
+++ b/Command/Get.hs
@@ -24,7 +24,7 @@ seek = [withField Command.Move.fromOption Remote.byName $ \from ->
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
start from file (key, _) = stopUnless (not <$> inAnnex key) $
- autoCopies file key (<) $ \_numcopies ->
+ autoCopies file key (<) $
case from of
Nothing -> go $ perform key file
Just src ->