2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010, 2013 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.Get where
|
|
|
|
|
|
|
|
import Command
|
2011-06-09 22:54:49 +00:00
|
|
|
import qualified Remote
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2014-03-22 14:42:38 +00:00
|
|
|
import Annex.Transfer
|
2015-04-30 18:02:56 +00:00
|
|
|
import Annex.NumCopies
|
2012-10-08 20:06:56 +00:00
|
|
|
import Annex.Wanted
|
2013-08-20 19:46:35 +00:00
|
|
|
import qualified Command.Move
|
2010-11-02 23:04:24 +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 "get" SectionCommon
|
|
|
|
"make content of annexed files available"
|
|
|
|
paramPaths (seek <$$> optParser)
|
2010-12-30 19:06:26 +00:00
|
|
|
|
2015-07-09 20:05:45 +00:00
|
|
|
data GetOptions = GetOptions
|
|
|
|
{ getFiles :: CmdParams
|
|
|
|
, getFrom :: Maybe (DeferredParse Remote)
|
|
|
|
, autoMode :: Bool
|
|
|
|
, keyOptions :: Maybe KeyOptions
|
2016-07-05 12:56:23 +00:00
|
|
|
, batchOption :: BatchMode
|
2015-07-09 20:05:45 +00:00
|
|
|
}
|
2013-07-03 17:55:50 +00:00
|
|
|
|
2015-07-09 20:05:45 +00:00
|
|
|
optParser :: CmdParamsDesc -> Parser GetOptions
|
|
|
|
optParser desc = GetOptions
|
|
|
|
<$> cmdParams desc
|
2017-05-31 20:20:55 +00:00
|
|
|
<*> optional (parseRemoteOption <$> parseFromOption)
|
2015-07-09 20:05:45 +00:00
|
|
|
<*> parseAutoOption
|
2016-08-03 16:37:12 +00:00
|
|
|
<*> optional (parseIncompleteOption <|> parseKeyOptions <|> parseFailedTransfersOption)
|
2016-07-05 12:56:23 +00:00
|
|
|
<*> parseBatchOption
|
2015-07-09 20:05:45 +00:00
|
|
|
|
|
|
|
seek :: GetOptions -> CommandSeek
|
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
|
|
|
seek o = startConcurrency transferStages $ do
|
2015-07-09 20:05:45 +00:00
|
|
|
from <- maybe (pure Nothing) (Just <$$> getParsed) (getFrom o)
|
2016-07-05 12:56:23 +00:00
|
|
|
let go = whenAnnexed $ start o from
|
|
|
|
case batchOption o of
|
added -z
Added -z option to git-annex commands that use --batch, useful for
supporting filenames containing newlines.
It only controls input to --batch, the output will still be line delimited
unless --json or etc is used to get some other output. While git often
makes -z affect both input and output, I don't like trying them together,
and making it affect output would have been a significant complication,
and also git-annex output is generally not intended to be machine parsed,
unless using --json or a format option.
Commands that take pairs like "file key" still separate them with a space
in --batch mode. All such commands take care to support filenames with
spaces when parsing that, so there was no need to change it, and it would
have needed significant changes to the batch machinery to separate tose
with a null.
To make fromkey and registerurl support -z, I had to give them a --batch
option. The implicit batch mode they enter when not provided with input
parameters does not support -z as that would have complicated option
parsing. Seemed better to move these toward using the same --batch as
everything else, though the implicit batch mode can still be used.
This commit was sponsored by Ole-Morten Duesund on Patreon.
2018-09-20 20:09:21 +00:00
|
|
|
Batch fmt -> batchFilesMatching fmt go
|
2016-07-05 12:56:23 +00:00
|
|
|
NoBatch -> withKeyOptions (keyOptions o) (autoMode o)
|
2018-10-01 18:12:06 +00:00
|
|
|
(commandAction . startKeys from)
|
|
|
|
(withFilesInGit (commandAction . go))
|
2017-10-16 18:10:03 +00:00
|
|
|
=<< workTreeItems (getFiles o)
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2015-07-09 20:05:45 +00:00
|
|
|
start :: GetOptions -> Maybe Remote -> FilePath -> Key -> CommandStart
|
2019-06-06 16:53:24 +00:00
|
|
|
start o from file key = start' expensivecheck from key afile ai
|
2013-07-03 17:55:50 +00:00
|
|
|
where
|
2017-03-10 17:12:24 +00:00
|
|
|
afile = AssociatedFile (Just file)
|
2019-06-06 16:53:24 +00:00
|
|
|
ai = mkActionItem (key, afile)
|
2015-03-25 21:06:14 +00:00
|
|
|
expensivecheck
|
2017-03-10 17:12:24 +00:00
|
|
|
| autoMode o = numCopiesCheck file key (<)
|
|
|
|
<||> wantGet False (Just key) afile
|
2015-03-25 21:06:14 +00:00
|
|
|
| otherwise = return True
|
2013-07-03 17:55:50 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
startKeys :: Maybe Remote -> (Key, ActionItem) -> CommandStart
|
|
|
|
startKeys from (key, ai) = checkFailedTransferDirection ai Download $
|
2017-03-10 17:12:24 +00:00
|
|
|
start' (return True) from key (AssociatedFile Nothing) ai
|
2013-07-03 17:55:50 +00:00
|
|
|
|
2016-07-20 19:22:55 +00:00
|
|
|
start' :: Annex Bool -> Maybe Remote -> Key -> AssociatedFile -> ActionItem -> CommandStart
|
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
|
|
|
start' expensivecheck from key afile ai =
|
2017-10-17 21:54:38 +00:00
|
|
|
stopUnless (not <$> inAnnex key) $ stopUnless expensivecheck $
|
2011-12-09 16:23:45 +00:00
|
|
|
case from of
|
2013-07-03 17:55:50 +00:00
|
|
|
Nothing -> go $ perform key afile
|
2012-06-12 15:32:06 +00:00
|
|
|
Just src ->
|
2011-12-09 16:23:45 +00:00
|
|
|
stopUnless (Command.Move.fromOk src key) $
|
2018-04-09 20:09:00 +00:00
|
|
|
go $ Command.Move.fromPerform src Command.Move.RemoveNever key afile
|
2012-11-12 05:05:04 +00:00
|
|
|
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 = starting "get" (OnlyActionOn key ai)
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2013-07-03 17:55:50 +00:00
|
|
|
perform :: Key -> AssociatedFile -> CommandPerform
|
Do verification of checksums of annex objects downloaded from remotes.
* When annex objects are received into git repositories, their checksums are
verified then too.
* To get the old, faster, behavior of not verifying checksums, set
annex.verify=false, or remote.<name>.annex-verify=false.
* setkey, rekey: These commands also now verify that the provided file
matches the key, unless annex.verify=false.
* reinject: Already verified content; this can now be disabled by
setting annex.verify=false.
recvkey and reinject already did verification, so removed now duplicate
code from them. fsck still does its own verification, which is ok since it
does not use getViaTmp, so verification doesn't happen twice when using fsck
--from.
2015-10-01 19:54:37 +00:00
|
|
|
perform key afile = stopUnless (getKey key afile) $
|
2011-12-09 16:23:45 +00:00
|
|
|
next $ return True -- no cleanup needed
|
2011-07-05 22:31:46 +00:00
|
|
|
|
|
|
|
{- Try to find a copy of the file in one of the remotes,
|
|
|
|
- and copy it to here. -}
|
Do verification of checksums of annex objects downloaded from remotes.
* When annex objects are received into git repositories, their checksums are
verified then too.
* To get the old, faster, behavior of not verifying checksums, set
annex.verify=false, or remote.<name>.annex-verify=false.
* setkey, rekey: These commands also now verify that the provided file
matches the key, unless annex.verify=false.
* reinject: Already verified content; this can now be disabled by
setting annex.verify=false.
recvkey and reinject already did verification, so removed now duplicate
code from them. fsck still does its own verification, which is ok since it
does not use getViaTmp, so verification doesn't happen twice when using fsck
--from.
2015-10-01 19:54:37 +00:00
|
|
|
getKey :: Key -> AssociatedFile -> Annex Bool
|
|
|
|
getKey key afile = getKey' key afile =<< Remote.keyPossibilities key
|
2014-01-19 21:35:36 +00:00
|
|
|
|
Do verification of checksums of annex objects downloaded from remotes.
* When annex objects are received into git repositories, their checksums are
verified then too.
* To get the old, faster, behavior of not verifying checksums, set
annex.verify=false, or remote.<name>.annex-verify=false.
* setkey, rekey: These commands also now verify that the provided file
matches the key, unless annex.verify=false.
* reinject: Already verified content; this can now be disabled by
setting annex.verify=false.
recvkey and reinject already did verification, so removed now duplicate
code from them. fsck still does its own verification, which is ok since it
does not use getViaTmp, so verification doesn't happen twice when using fsck
--from.
2015-10-01 19:54:37 +00:00
|
|
|
getKey' :: Key -> AssociatedFile -> [Remote] -> Annex Bool
|
|
|
|
getKey' key afile = dispatch
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
dispatch [] = do
|
|
|
|
showNote "not available"
|
2013-01-09 22:53:59 +00:00
|
|
|
showlocs
|
2012-11-12 05:05:04 +00:00
|
|
|
return False
|
2016-09-06 16:42:50 +00:00
|
|
|
dispatch remotes = notifyTransfer Download afile $ \witness -> do
|
|
|
|
ok <- pickRemote remotes $ \r -> ifM (probablyPresent r)
|
|
|
|
( docopy r witness
|
|
|
|
, return False
|
2012-11-12 05:05:04 +00:00
|
|
|
)
|
2016-09-06 16:42:50 +00:00
|
|
|
if ok
|
|
|
|
then return ok
|
|
|
|
else do
|
|
|
|
Remote.showTriedRemotes remotes
|
|
|
|
showlocs
|
|
|
|
return False
|
2015-01-16 17:29:54 +00:00
|
|
|
showlocs = Remote.showLocations False key []
|
2013-01-09 22:53:59 +00:00
|
|
|
"No other repository is known to contain the file."
|
2012-11-12 05:05:04 +00:00
|
|
|
-- This check is to avoid an ugly message if a remote is a
|
|
|
|
-- drive that is not mounted.
|
|
|
|
probablyPresent r
|
|
|
|
| Remote.hasKeyCheap r =
|
|
|
|
either (const False) id <$> Remote.hasKey r key
|
|
|
|
| otherwise = return True
|
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
|
|
|
docopy r witness = getViaTmp (Remote.retrievalSecurityPolicy r) (RemoteVerify r) key $ \dest ->
|
2018-03-29 17:04:07 +00:00
|
|
|
download (Remote.uuid r) key afile stdRetry
|
2017-10-17 21:54:38 +00:00
|
|
|
(\p -> do
|
Do verification of checksums of annex objects downloaded from remotes.
* When annex objects are received into git repositories, their checksums are
verified then too.
* To get the old, faster, behavior of not verifying checksums, set
annex.verify=false, or remote.<name>.annex-verify=false.
* setkey, rekey: These commands also now verify that the provided file
matches the key, unless annex.verify=false.
* reinject: Already verified content; this can now be disabled by
setting annex.verify=false.
recvkey and reinject already did verification, so removed now duplicate
code from them. fsck still does its own verification, which is ok since it
does not use getViaTmp, so verification doesn't happen twice when using fsck
--from.
2015-10-01 19:54:37 +00:00
|
|
|
showAction $ "from " ++ Remote.name r
|
|
|
|
Remote.retrieveKeyFile r key afile dest p
|
2017-10-17 21:54:38 +00:00
|
|
|
) witness
|