copy, drop: Avoid checking numcopies attribute unnecessarily
This commit is contained in:
parent
619297e1a7
commit
aa558f0b00
4 changed files with 16 additions and 5 deletions
15
Command.hs
15
Command.hs
|
@ -21,6 +21,7 @@ module Command (
|
||||||
isBareRepo,
|
isBareRepo,
|
||||||
numCopies,
|
numCopies,
|
||||||
autoCopies,
|
autoCopies,
|
||||||
|
autoCopiesWith,
|
||||||
module ReExported
|
module ReExported
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
@ -112,8 +113,18 @@ numCopies file = readish <$> checkAttr "annex.numcopies" file
|
||||||
- In auto mode, first checks that the number of known
|
- In auto mode, first checks that the number of known
|
||||||
- copies of the key is > or < than the numcopies setting, before running
|
- copies of the key is > or < than the numcopies setting, before running
|
||||||
- the action. -}
|
- the action. -}
|
||||||
autoCopies :: FilePath -> Key -> (Int -> Int -> Bool) -> (Maybe Int -> CommandStart) -> CommandStart
|
autoCopies :: FilePath -> Key -> (Int -> Int -> Bool) -> CommandStart -> CommandStart
|
||||||
autoCopies file key vs a = do
|
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
|
numcopiesattr <- numCopies file
|
||||||
Annex.getState Annex.auto >>= auto numcopiesattr
|
Annex.getState Annex.auto >>= auto numcopiesattr
|
||||||
where
|
where
|
||||||
|
|
|
@ -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.
|
-- A copy is just a move that does not delete the source file.
|
||||||
-- However, --auto mode avoids unnecessary copies.
|
-- However, --auto mode avoids unnecessary copies.
|
||||||
start :: Maybe Remote -> Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
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)
|
Command.Move.start to from False file (key, backend)
|
||||||
|
|
|
@ -30,7 +30,7 @@ seek = [withField fromOption Remote.byName $ \from ->
|
||||||
withFilesInGit $ whenAnnexed $ start from]
|
withFilesInGit $ whenAnnexed $ start from]
|
||||||
|
|
||||||
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
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
|
case from of
|
||||||
Nothing -> startLocal file numcopies key
|
Nothing -> startLocal file numcopies key
|
||||||
Just remote -> do
|
Just remote -> do
|
||||||
|
|
|
@ -24,7 +24,7 @@ seek = [withField Command.Move.fromOption Remote.byName $ \from ->
|
||||||
|
|
||||||
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
||||||
start from file (key, _) = stopUnless (not <$> inAnnex key) $
|
start from file (key, _) = stopUnless (not <$> inAnnex key) $
|
||||||
autoCopies file key (<) $ \_numcopies ->
|
autoCopies file key (<) $
|
||||||
case from of
|
case from of
|
||||||
Nothing -> go $ perform key file
|
Nothing -> go $ perform key file
|
||||||
Just src ->
|
Just src ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue