2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2018-04-09 20:09:00 +00:00
|
|
|
- Copyright 2010-2018 Joey Hess <id@joeyh.name>
|
2010-11-02 23:04:24 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2010-11-02 23:04:24 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Move where
|
|
|
|
|
|
|
|
import Command
|
2010-11-11 22:54:52 +00:00
|
|
|
import qualified Command.Drop
|
2010-11-02 23:04:24 +00:00
|
|
|
import qualified Annex
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2011-03-27 21:24:20 +00:00
|
|
|
import qualified Remote
|
2011-10-15 21:47:03 +00:00
|
|
|
import Annex.UUID
|
2014-03-22 14:42:38 +00:00
|
|
|
import Annex.Transfer
|
2012-01-19 19:24:05 +00:00
|
|
|
import Logs.Presence
|
2018-04-13 18:06:25 +00:00
|
|
|
import Logs.Trust
|
2015-10-09 20:16:03 +00:00
|
|
|
import Annex.NumCopies
|
|
|
|
|
|
|
|
import System.Log.Logger (debugM)
|
2011-03-16 01:34:13 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2018-02-19 18:28:17 +00:00
|
|
|
cmd = withGlobalOptions [jobsOption, jsonOptions, jsonProgressOption, annexedMatchingOptions] $
|
2015-07-10 17:18:46 +00:00
|
|
|
command "move" SectionCommon
|
|
|
|
"move content of files to/from another repository"
|
|
|
|
paramPaths (seek <--< optParser)
|
2015-07-09 19:23:14 +00:00
|
|
|
|
|
|
|
data MoveOptions = MoveOptions
|
|
|
|
{ moveFiles :: CmdParams
|
2018-04-09 18:29:28 +00:00
|
|
|
, fromToOptions :: FromToHereOptions
|
2018-04-13 18:06:25 +00:00
|
|
|
, removeWhen :: RemoveWhen
|
2015-07-09 19:23:14 +00:00
|
|
|
, keyOptions :: Maybe KeyOptions
|
2017-08-15 16:39:10 +00:00
|
|
|
, batchOption :: BatchMode
|
2015-07-09 19:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
optParser :: CmdParamsDesc -> Parser MoveOptions
|
|
|
|
optParser desc = MoveOptions
|
|
|
|
<$> cmdParams desc
|
2018-04-09 18:29:28 +00:00
|
|
|
<*> parseFromToHereOptions
|
2018-04-13 18:06:25 +00:00
|
|
|
<*> pure RemoveSafe
|
2016-08-03 16:37:12 +00:00
|
|
|
<*> optional (parseKeyOptions <|> parseFailedTransfersOption)
|
2017-08-15 16:39:10 +00:00
|
|
|
<*> parseBatchOption
|
2015-07-09 19:23:14 +00:00
|
|
|
|
|
|
|
instance DeferredParseClass MoveOptions where
|
|
|
|
finishParse v = MoveOptions
|
|
|
|
<$> pure (moveFiles v)
|
2018-04-09 18:29:28 +00:00
|
|
|
<*> finishParse (fromToOptions v)
|
2018-04-13 18:06:25 +00:00
|
|
|
<*> pure (removeWhen v)
|
2015-07-09 19:23:14 +00:00
|
|
|
<*> pure (keyOptions v)
|
2017-08-15 16:39:10 +00:00
|
|
|
<*> pure (batchOption v)
|
2015-07-09 19:23:14 +00:00
|
|
|
|
2018-04-13 18:06:25 +00:00
|
|
|
data RemoveWhen = RemoveSafe | RemoveNever
|
2018-04-09 20:09:00 +00:00
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2015-07-09 19:23:14 +00:00
|
|
|
seek :: MoveOptions -> CommandSeek
|
2020-05-26 15:55:50 +00:00
|
|
|
seek o = startConcurrency stages $ do
|
2017-08-15 16:39:10 +00:00
|
|
|
case batchOption o of
|
2020-07-24 16:05:28 +00:00
|
|
|
NoBatch -> withKeyOptions (keyOptions o) False seeker
|
2018-10-01 18:12:06 +00:00
|
|
|
(commandAction . startKey (fromToOptions o) (removeWhen o))
|
2020-07-13 21:04:02 +00:00
|
|
|
(withFilesInGitAnnex ww seeker)
|
2020-05-28 19:55:17 +00:00
|
|
|
=<< workTreeItems ww (moveFiles o)
|
2020-07-22 18:23:28 +00:00
|
|
|
Batch fmt -> batchAnnexedFilesMatching fmt seeker
|
2020-05-26 15:55:50 +00:00
|
|
|
where
|
2020-07-24 16:56:02 +00:00
|
|
|
seeker = AnnexedFileSeeker
|
|
|
|
{ startAction = start (fromToOptions o) (removeWhen o)
|
|
|
|
, checkContentPresent = case fromToOptions o of
|
|
|
|
Right (FromRemote _) -> Nothing
|
|
|
|
Right (ToRemote _) -> Just True
|
|
|
|
Left ToHere -> Nothing
|
|
|
|
, usesLocationLog = True
|
|
|
|
}
|
2020-05-26 15:55:50 +00:00
|
|
|
stages = case fromToOptions o of
|
|
|
|
Right (FromRemote _) -> downloadStages
|
|
|
|
Right (ToRemote _) -> commandStages
|
|
|
|
Left ToHere -> downloadStages
|
2020-05-28 19:55:17 +00:00
|
|
|
ww = WarnUnmatchLsFiles
|
2015-07-09 19:23:14 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
start :: FromToHereOptions -> RemoveWhen -> SeekInput -> RawFilePath -> Key -> CommandStart
|
|
|
|
start fromto removewhen si f k = start' fromto removewhen afile si k ai
|
2016-07-20 19:22:55 +00:00
|
|
|
where
|
2017-03-10 17:12:24 +00:00
|
|
|
afile = AssociatedFile (Just f)
|
2019-06-06 16:53:24 +00:00
|
|
|
ai = mkActionItem (k, afile)
|
2015-07-09 19:23:14 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
startKey :: FromToHereOptions -> RemoveWhen -> (SeekInput, Key, ActionItem) -> CommandStart
|
|
|
|
startKey fromto removewhen (si, k, ai) =
|
|
|
|
start' fromto removewhen (AssociatedFile Nothing) si k ai
|
2015-07-09 19:23:14 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
start' :: FromToHereOptions -> RemoveWhen -> AssociatedFile -> SeekInput -> Key -> ActionItem -> CommandStart
|
|
|
|
start' fromto removewhen afile si key ai =
|
2018-04-09 18:38:46 +00:00
|
|
|
case fromto of
|
2017-05-31 20:20:55 +00:00
|
|
|
Right (FromRemote src) ->
|
|
|
|
checkFailedTransferDirection ai Download $
|
2020-09-14 20:49:33 +00:00
|
|
|
fromStart removewhen afile key ai si =<< getParsed src
|
2017-05-31 20:20:55 +00:00
|
|
|
Right (ToRemote dest) ->
|
|
|
|
checkFailedTransferDirection ai Upload $
|
2020-09-14 20:49:33 +00:00
|
|
|
toStart removewhen afile key ai si =<< getParsed dest
|
move --to=here
* move --to=here moves from all reachable remotes to the local repository.
The output of move --from remote is changed slightly, when the remote and
local both have the content. It used to say:
move foo ok
Now:
move foo (from theremote...) ok
That was done so that, when move --to=here is used and the content is
locally present and also in several remotes, it's clear which remotes the
content gets dropped from.
Note that move --to=here will report an error if a non-reachable remote
contains the file, even if the local repository also contains the file. I
think that's reasonable; the user may be intending to move all other copies
of the file from remotes.
OTOH, if a copy of the file is believed to be present in some repository
that is not a configured remote, move --to=here does not report an error.
So a little bit inconsistent, but erroring in this case feels wrong.
copy --to=here came along for free, but it's basically the same behavior as
git-annex get, and probably with not as good messages in edge cases
(especially on failure), so I've not documented it.
This commit was sponsored by Anthony DeRobertis on Patreon.
2017-05-31 20:57:27 +00:00
|
|
|
Left ToHere ->
|
|
|
|
checkFailedTransferDirection ai Download $
|
2020-09-14 20:49:33 +00:00
|
|
|
toHereStart removewhen afile key ai si
|
2010-11-02 23:04:24 +00:00
|
|
|
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
describeMoveAction :: RemoveWhen -> String
|
|
|
|
describeMoveAction RemoveNever = "copy"
|
|
|
|
describeMoveAction _ = "move"
|
2010-11-27 21:02:53 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
toStart :: RemoveWhen -> AssociatedFile -> Key -> ActionItem -> SeekInput -> Remote -> CommandStart
|
|
|
|
toStart removewhen afile key ai si dest = do
|
2011-10-11 18:43:45 +00:00
|
|
|
u <- getUUID
|
2020-07-24 16:56:02 +00:00
|
|
|
if u == Remote.uuid dest
|
|
|
|
then stop
|
2020-09-14 20:49:33 +00:00
|
|
|
else toStart' dest removewhen afile key ai si
|
2014-03-13 18:51:22 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
toStart' :: Remote -> RemoveWhen -> AssociatedFile -> Key -> ActionItem -> SeekInput -> CommandStart
|
|
|
|
toStart' dest removewhen afile key ai si = do
|
2011-03-27 22:34:30 +00:00
|
|
|
fast <- Annex.getState Annex.fast
|
2018-04-09 20:09:00 +00:00
|
|
|
if fast && removewhen == RemoveNever
|
2014-03-13 18:51:22 +00:00
|
|
|
then ifM (expectedPresent dest key)
|
|
|
|
( stop
|
|
|
|
, go True (pure $ Right False)
|
|
|
|
)
|
|
|
|
else go False (Remote.hasKey dest key)
|
|
|
|
where
|
finish CommandStart transition
The hoped for optimisation of CommandStart with -J did not materialize.
In fact, not runnign CommandStart in parallel is slower than -J3.
So, CommandStart are still run in parallel.
(The actual bad performance I've been seeing with -J in my big repo
has to do with building the remoteList.)
But, this is still progress toward making -J faster, because it gets rid
of the onlyActionOn roadblock in the way of making CommandCleanup jobs
run separate from CommandPerform jobs.
Added OnlyActionOn constructor for ActionItem which fixes the
onlyActionOn breakage in the last commit.
Made CustomOutput include an ActionItem, so even things using it can
specify OnlyActionOn.
In Command.Move and Command.Sync, there were CommandStarts that used
includeCommandAction, so output messages, which is no longer allowed.
Fixed by using startingCustomOutput, but that's still not quite right,
since it prevents message display for the includeCommandAction run
inside it too.
2019-06-12 13:23:26 +00:00
|
|
|
go fastcheck isthere =
|
2020-09-14 20:49:33 +00:00
|
|
|
starting (describeMoveAction removewhen) (OnlyActionOn key ai) si $
|
finish CommandStart transition
The hoped for optimisation of CommandStart with -J did not materialize.
In fact, not runnign CommandStart in parallel is slower than -J3.
So, CommandStart are still run in parallel.
(The actual bad performance I've been seeing with -J in my big repo
has to do with building the remoteList.)
But, this is still progress toward making -J faster, because it gets rid
of the onlyActionOn roadblock in the way of making CommandCleanup jobs
run separate from CommandPerform jobs.
Added OnlyActionOn constructor for ActionItem which fixes the
onlyActionOn breakage in the last commit.
Made CustomOutput include an ActionItem, so even things using it can
specify OnlyActionOn.
In Command.Move and Command.Sync, there were CommandStarts that used
includeCommandAction, so output messages, which is no longer allowed.
Fixed by using startingCustomOutput, but that's still not quite right,
since it prevents message display for the includeCommandAction run
inside it too.
2019-06-12 13:23:26 +00:00
|
|
|
toPerform dest removewhen key afile fastcheck =<< isthere
|
2014-03-13 18:51:22 +00:00
|
|
|
|
|
|
|
expectedPresent :: Remote -> Key -> Annex Bool
|
|
|
|
expectedPresent dest key = do
|
|
|
|
remotes <- Remote.keyPossibilities key
|
|
|
|
return $ dest `elem` remotes
|
|
|
|
|
2018-04-09 20:09:00 +00:00
|
|
|
toPerform :: Remote -> RemoveWhen -> Key -> AssociatedFile -> Bool -> Either String Bool -> CommandPerform
|
|
|
|
toPerform dest removewhen key afile fastcheck isthere =
|
2010-11-02 23:04:24 +00:00
|
|
|
case isthere of
|
|
|
|
Left err -> do
|
2011-11-11 05:52:58 +00:00
|
|
|
showNote err
|
2011-05-15 06:02:46 +00:00
|
|
|
stop
|
2010-11-02 23:04:24 +00:00
|
|
|
Right False -> do
|
2011-07-19 18:07:23 +00:00
|
|
|
showAction $ "to " ++ Remote.name dest
|
2014-03-22 14:42:38 +00:00
|
|
|
ok <- notifyTransfer Upload afile $
|
2020-05-14 18:19:28 +00:00
|
|
|
upload (Remote.uuid dest) key afile stdRetry $
|
|
|
|
Remote.action . Remote.storeKey dest key afile
|
2010-11-22 21:51:55 +00:00
|
|
|
if ok
|
2018-04-13 18:06:25 +00:00
|
|
|
then finish False $
|
2013-02-26 18:39:37 +00:00
|
|
|
Remote.logStatus dest key InfoPresent
|
2011-05-16 17:27:19 +00:00
|
|
|
else do
|
|
|
|
when fastcheck $
|
|
|
|
warning "This could have failed because --fast is enabled."
|
|
|
|
stop
|
2018-04-13 18:06:25 +00:00
|
|
|
Right True -> finish True $
|
2014-03-13 18:51:22 +00:00
|
|
|
unlessM (expectedPresent dest key) $
|
2013-02-26 18:39:37 +00:00
|
|
|
Remote.logStatus dest key InfoPresent
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2018-04-13 18:06:25 +00:00
|
|
|
finish deststartedwithcopy setpresentremote = case removewhen of
|
2018-04-09 20:09:00 +00:00
|
|
|
RemoveNever -> do
|
2016-06-05 17:51:22 +00:00
|
|
|
setpresentremote
|
2018-04-09 20:09:00 +00:00
|
|
|
next $ return True
|
2020-07-25 15:54:34 +00:00
|
|
|
RemoveSafe -> lockContentForRemoval key lockfailed $ \contentlock -> do
|
2018-04-13 18:06:25 +00:00
|
|
|
srcuuid <- getUUID
|
|
|
|
let destuuid = Remote.uuid dest
|
|
|
|
willDropMakeItWorse srcuuid destuuid deststartedwithcopy key afile >>= \case
|
|
|
|
DropAllowed -> drophere setpresentremote contentlock "moved"
|
|
|
|
DropCheckNumCopies -> do
|
|
|
|
numcopies <- getAssociatedFileNumCopies afile
|
|
|
|
(tocheck, verified) <- verifiableCopies key [srcuuid]
|
|
|
|
verifyEnoughCopiesToDrop "" key (Just contentlock)
|
|
|
|
numcopies [srcuuid] verified
|
|
|
|
(UnVerifiedRemote dest : tocheck)
|
|
|
|
(drophere setpresentremote contentlock . showproof)
|
|
|
|
(faileddrophere setpresentremote)
|
|
|
|
DropWorse -> faileddrophere setpresentremote
|
|
|
|
showproof proof = "proof: " ++ show proof
|
|
|
|
drophere setpresentremote contentlock reason = do
|
|
|
|
liftIO $ debugM "move" $ unwords
|
|
|
|
[ "Dropping from here"
|
|
|
|
, "(" ++ reason ++ ")"
|
|
|
|
]
|
|
|
|
-- Drop content before updating location logs,
|
|
|
|
-- in case disk space is very low this frees
|
|
|
|
-- up space before writing data to disk.
|
|
|
|
removeAnnex contentlock
|
|
|
|
next $ do
|
|
|
|
() <- setpresentremote
|
|
|
|
Command.Drop.cleanupLocal key
|
|
|
|
faileddrophere setpresentremote = do
|
|
|
|
showLongNote "(Use --force to override this check, or adjust numcopies.)"
|
|
|
|
showLongNote "Content not dropped from here."
|
|
|
|
next $ do
|
|
|
|
() <- setpresentremote
|
|
|
|
return False
|
2020-07-25 15:54:34 +00:00
|
|
|
|
|
|
|
-- This occurs when, for example, two files are being dropped
|
|
|
|
-- and have the same content. The seek stage checks if the content
|
|
|
|
-- is present, but due to buffering, may find it present for the
|
|
|
|
-- second file before the first is dropped. If so, nothing remains
|
|
|
|
-- to be done except for cleaning up.
|
|
|
|
lockfailed = next $ Command.Drop.cleanupLocal key
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
fromStart :: RemoveWhen -> AssociatedFile -> Key -> ActionItem -> SeekInput -> Remote -> CommandStart
|
|
|
|
fromStart removewhen afile key ai si src =
|
2020-07-24 16:56:02 +00:00
|
|
|
stopUnless (fromOk src key) $
|
2020-09-14 20:49:33 +00:00
|
|
|
starting (describeMoveAction removewhen) (OnlyActionOn key ai) si $
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
fromPerform src removewhen key afile
|
2012-11-12 05:05:04 +00:00
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
fromOk :: Remote -> Key -> Annex Bool
|
fix bug involving local git remote and out of date location log
get --from, move --from: When used with a local git remote, these used to
silently skip files that the location log thought were present on the
remote, when the remote actually no longer contained them. Since that
behavior could be surprising, now instead display a warning.
I got very confused when I encountered this behavior, since it was silently
skipping a file I needed that whereis said was on the remote.
get without --from already displayed a "unable to access these remotes"
message, which while a bit misleading in that the remote is likely
accessible, but just doesn't contain the file, at least indicated something
went wrong.
Having get --from display a warning makes it in line with get
w/o --from, so seems certianly ok. It might be there are situations where
move --from is used, on eg a whole directory, and the user only wants to
move whatever is present in the remote, and is perfectly ok with files
that are not present being skipped. So I'm less sure about the new warning
being ok there. OTOH, only local git remotes avoiding displaying a warning
in that case too, so this just brings them into line with other remotes.
(Also note that this makes it a little bit faster when dealing with a lot of
files, since it avoids a redundant stat of the file.)
2020-04-21 16:36:58 +00:00
|
|
|
fromOk src key = do
|
|
|
|
u <- getUUID
|
|
|
|
remotes <- Remote.keyPossibilities key
|
|
|
|
return $ u /= Remote.uuid src && elem src remotes
|
2012-11-12 05:05:04 +00:00
|
|
|
|
2018-04-09 20:09:00 +00:00
|
|
|
fromPerform :: Remote -> RemoveWhen -> Key -> AssociatedFile -> CommandPerform
|
|
|
|
fromPerform src removewhen key afile = do
|
move --to=here
* move --to=here moves from all reachable remotes to the local repository.
The output of move --from remote is changed slightly, when the remote and
local both have the content. It used to say:
move foo ok
Now:
move foo (from theremote...) ok
That was done so that, when move --to=here is used and the content is
locally present and also in several remotes, it's clear which remotes the
content gets dropped from.
Note that move --to=here will report an error if a non-reachable remote
contains the file, even if the local repository also contains the file. I
think that's reasonable; the user may be intending to move all other copies
of the file from remotes.
OTOH, if a copy of the file is believed to be present in some repository
that is not a configured remote, move --to=here does not report an error.
So a little bit inconsistent, but erroring in this case feels wrong.
copy --to=here came along for free, but it's basically the same behavior as
git-annex get, and probably with not as good messages in edge cases
(especially on failure), so I've not documented it.
This commit was sponsored by Anthony DeRobertis on Patreon.
2017-05-31 20:57:27 +00:00
|
|
|
showAction $ "from " ++ Remote.name src
|
|
|
|
ifM (inAnnex key)
|
2018-04-13 18:06:25 +00:00
|
|
|
( dispatch removewhen True True
|
|
|
|
, dispatch removewhen False =<< go
|
move --to=here
* move --to=here moves from all reachable remotes to the local repository.
The output of move --from remote is changed slightly, when the remote and
local both have the content. It used to say:
move foo ok
Now:
move foo (from theremote...) ok
That was done so that, when move --to=here is used and the content is
locally present and also in several remotes, it's clear which remotes the
content gets dropped from.
Note that move --to=here will report an error if a non-reachable remote
contains the file, even if the local repository also contains the file. I
think that's reasonable; the user may be intending to move all other copies
of the file from remotes.
OTOH, if a copy of the file is believed to be present in some repository
that is not a configured remote, move --to=here does not report an error.
So a little bit inconsistent, but erroring in this case feels wrong.
copy --to=here came along for free, but it's basically the same behavior as
git-annex get, and probably with not as good messages in edge cases
(especially on failure), so I've not documented it.
This commit was sponsored by Anthony DeRobertis on Patreon.
2017-05-31 20:57:27 +00:00
|
|
|
)
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2014-03-22 14:42:38 +00:00
|
|
|
go = notifyTransfer Download afile $
|
2018-03-29 17:04:07 +00:00
|
|
|
download (Remote.uuid src) key afile stdRetry $ \p ->
|
use fine-grained WorkerStages when transferring and verifying
This means that Command.Move and Command.Get don't need to
manually set the stage, and is a lot cleaner conceptually.
Also, this makes Command.Sync.syncFile use the worker pool better.
In the scenario where it first downloads content and then uploads it to
some other remotes, it will start in TransferStage, then enter VerifyStage
and then go back to TransferStage for each transfer to the remotes.
Before, it entered CleanupStage after the download, and stayed in it for
the upload, so too many transfer jobs could run at the same time.
Note that, in Remote.Git, it uses runTransfer and also verifyKeyContent
inside onLocal. That has a Annex state for the remote, with no worker pool.
So the resulting calls to enteringStage won't block in there.
While Remote.Git.copyToRemote does do checksum verification, I
realized that should not use a verification slot in the WorkerPool
to do it. Because, it's reading back from eg, a removable disk to checksum.
That will contend with other writes to that disk. It's best to treat
that checksum verification as just part of the transer. So, removed the todo
item about that, as there's nothing needing to be done.
2019-06-19 17:09:26 +00:00
|
|
|
getViaTmp (Remote.retrievalSecurityPolicy src) (RemoteVerify src) key $ \t ->
|
2020-05-14 18:19:28 +00:00
|
|
|
Remote.verifiedAction $ Remote.retrieveKeyFile src key afile t p
|
2018-04-13 18:06:25 +00:00
|
|
|
dispatch _ _ False = stop -- failed
|
|
|
|
dispatch RemoveNever _ True = next $ return True -- copy complete
|
|
|
|
dispatch RemoveSafe deststartedwithcopy True = lockContentShared key $ \_lck -> do
|
|
|
|
let srcuuid = Remote.uuid src
|
|
|
|
destuuid <- getUUID
|
|
|
|
willDropMakeItWorse srcuuid destuuid deststartedwithcopy key afile >>= \case
|
|
|
|
DropAllowed -> dropremote "moved"
|
|
|
|
DropCheckNumCopies -> do
|
|
|
|
numcopies <- getAssociatedFileNumCopies afile
|
|
|
|
(tocheck, verified) <- verifiableCopies key [Remote.uuid src]
|
|
|
|
verifyEnoughCopiesToDrop "" key Nothing numcopies [Remote.uuid src] verified
|
|
|
|
tocheck (dropremote . showproof) faileddropremote
|
|
|
|
DropWorse -> faileddropremote
|
|
|
|
showproof proof = "proof: " ++ show proof
|
|
|
|
dropremote reason = do
|
|
|
|
liftIO $ debugM "move" $ unwords
|
2015-10-09 20:16:03 +00:00
|
|
|
[ "Dropping from remote"
|
|
|
|
, show src
|
2018-04-13 18:06:25 +00:00
|
|
|
, "(" ++ reason ++ ")"
|
2015-10-09 20:16:03 +00:00
|
|
|
]
|
2020-05-14 18:19:28 +00:00
|
|
|
ok <- Remote.action (Remote.removeKey src key)
|
2012-11-12 05:05:04 +00:00
|
|
|
next $ Command.Drop.cleanupRemote key src ok
|
2018-04-13 18:06:25 +00:00
|
|
|
faileddropremote = do
|
|
|
|
showLongNote "(Use --force to override this check, or adjust numcopies.)"
|
|
|
|
showLongNote $ "Content not dropped from " ++ Remote.name src ++ "."
|
|
|
|
next $ return False
|
move --to=here
* move --to=here moves from all reachable remotes to the local repository.
The output of move --from remote is changed slightly, when the remote and
local both have the content. It used to say:
move foo ok
Now:
move foo (from theremote...) ok
That was done so that, when move --to=here is used and the content is
locally present and also in several remotes, it's clear which remotes the
content gets dropped from.
Note that move --to=here will report an error if a non-reachable remote
contains the file, even if the local repository also contains the file. I
think that's reasonable; the user may be intending to move all other copies
of the file from remotes.
OTOH, if a copy of the file is believed to be present in some repository
that is not a configured remote, move --to=here does not report an error.
So a little bit inconsistent, but erroring in this case feels wrong.
copy --to=here came along for free, but it's basically the same behavior as
git-annex get, and probably with not as good messages in edge cases
(especially on failure), so I've not documented it.
This commit was sponsored by Anthony DeRobertis on Patreon.
2017-05-31 20:57:27 +00:00
|
|
|
|
|
|
|
{- Moves (or copies) the content of an annexed file from reachable remotes
|
|
|
|
- to the current repository.
|
|
|
|
-
|
2018-04-13 18:06:25 +00:00
|
|
|
- When moving, the content is removed from all the reachable remotes that
|
|
|
|
- it can safely be removed from. -}
|
2020-09-14 20:49:33 +00:00
|
|
|
toHereStart :: RemoveWhen -> AssociatedFile -> Key -> ActionItem -> SeekInput -> CommandStart
|
|
|
|
toHereStart removewhen afile key ai si =
|
2020-07-24 16:56:02 +00:00
|
|
|
startingNoMessage (OnlyActionOn key ai) $ do
|
move --to=here
* move --to=here moves from all reachable remotes to the local repository.
The output of move --from remote is changed slightly, when the remote and
local both have the content. It used to say:
move foo ok
Now:
move foo (from theremote...) ok
That was done so that, when move --to=here is used and the content is
locally present and also in several remotes, it's clear which remotes the
content gets dropped from.
Note that move --to=here will report an error if a non-reachable remote
contains the file, even if the local repository also contains the file. I
think that's reasonable; the user may be intending to move all other copies
of the file from remotes.
OTOH, if a copy of the file is believed to be present in some repository
that is not a configured remote, move --to=here does not report an error.
So a little bit inconsistent, but erroring in this case feels wrong.
copy --to=here came along for free, but it's basically the same behavior as
git-annex get, and probably with not as good messages in edge cases
(especially on failure), so I've not documented it.
This commit was sponsored by Anthony DeRobertis on Patreon.
2017-05-31 20:57:27 +00:00
|
|
|
rs <- Remote.keyPossibilities key
|
|
|
|
forM_ rs $ \r ->
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
includeCommandAction $
|
2020-09-14 20:49:33 +00:00
|
|
|
starting (describeMoveAction removewhen) ai si $
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
fromPerform r removewhen key afile
|
finish CommandStart transition
The hoped for optimisation of CommandStart with -J did not materialize.
In fact, not runnign CommandStart in parallel is slower than -J3.
So, CommandStart are still run in parallel.
(The actual bad performance I've been seeing with -J in my big repo
has to do with building the remoteList.)
But, this is still progress toward making -J faster, because it gets rid
of the onlyActionOn roadblock in the way of making CommandCleanup jobs
run separate from CommandPerform jobs.
Added OnlyActionOn constructor for ActionItem which fixes the
onlyActionOn breakage in the last commit.
Made CustomOutput include an ActionItem, so even things using it can
specify OnlyActionOn.
In Command.Move and Command.Sync, there were CommandStarts that used
includeCommandAction, so output messages, which is no longer allowed.
Fixed by using startingCustomOutput, but that's still not quite right,
since it prevents message display for the includeCommandAction run
inside it too.
2019-06-12 13:23:26 +00:00
|
|
|
next $ return True
|
2018-04-13 18:06:25 +00:00
|
|
|
|
|
|
|
{- The goal of this command is to allow the user maximum freedom to move
|
|
|
|
- files as they like, while avoiding making bad situations any worse
|
|
|
|
- than they already were.
|
|
|
|
-
|
|
|
|
- When the destination repository already had a copy of a file
|
|
|
|
- before the move operation began, dropping it from the source
|
|
|
|
- repository reduces the number of copies, and should fail if
|
|
|
|
- that would violate numcopies settings.
|
|
|
|
-
|
|
|
|
- On the other hand, when the destiation repository does not already
|
|
|
|
- have a copy of a file, it can be dropped without making numcopies
|
|
|
|
- worse, so the move is allowed even if numcopies is not met.
|
|
|
|
-
|
|
|
|
- Similarly, a file can move from an untrusted repository to another
|
|
|
|
- untrusted repository, even if that is the only copy of the file.
|
|
|
|
-
|
|
|
|
- But, moving a file from a repository with higher trust to an untrusted
|
|
|
|
- repository must still check that there are enough other copies to be
|
|
|
|
- safe.
|
|
|
|
-
|
|
|
|
- Also, required content settings should not be violated.
|
|
|
|
-
|
|
|
|
- This function checks all that. It needs to know if the destination
|
|
|
|
- repository already had a copy of the file before the move began.
|
|
|
|
-}
|
|
|
|
willDropMakeItWorse :: UUID -> UUID -> Bool -> Key -> AssociatedFile -> Annex DropCheck
|
|
|
|
willDropMakeItWorse srcuuid destuuid deststartedwithcopy key afile =
|
|
|
|
ifM (Command.Drop.checkRequiredContent srcuuid key afile)
|
|
|
|
( if deststartedwithcopy
|
|
|
|
then unlessforced DropCheckNumCopies
|
|
|
|
else ifM checktrustlevel
|
|
|
|
( return DropAllowed
|
|
|
|
, unlessforced DropCheckNumCopies
|
|
|
|
)
|
|
|
|
, unlessforced DropWorse
|
|
|
|
)
|
|
|
|
where
|
|
|
|
unlessforced r = ifM (Annex.getState Annex.force)
|
|
|
|
( return DropAllowed
|
|
|
|
, return r
|
|
|
|
)
|
|
|
|
checktrustlevel = do
|
|
|
|
desttrust <- lookupTrust destuuid
|
|
|
|
srctrust <- lookupTrust srcuuid
|
2018-04-13 19:16:07 +00:00
|
|
|
return (desttrust > UnTrusted || desttrust >= srctrust)
|
2018-04-13 18:06:25 +00:00
|
|
|
|
|
|
|
data DropCheck = DropWorse | DropAllowed | DropCheckNumCopies
|