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
|
2020-05-26 15:55:50 +00:00
|
|
|
seek o = startConcurrency downloadStages $ do
|
2015-07-09 20:05:45 +00:00
|
|
|
from <- maybe (pure Nothing) (Just <$$> getParsed) (getFrom o)
|
2020-07-13 21:04:02 +00:00
|
|
|
let seeker = AnnexedFileSeeker
|
2020-07-22 18:23:28 +00:00
|
|
|
{ startAction = start o from
|
2020-07-13 21:04:02 +00:00
|
|
|
, checkContentPresent = Just False
|
|
|
|
, usesLocationLog = True
|
|
|
|
}
|
2016-07-05 12:56:23 +00:00
|
|
|
case batchOption o of
|
2020-07-24 16:05:28 +00:00
|
|
|
NoBatch -> withKeyOptions (keyOptions o) (autoMode o) seeker
|
2018-10-01 18:12:06 +00:00
|
|
|
(commandAction . startKeys from)
|
2020-07-13 21:04:02 +00:00
|
|
|
(withFilesInGitAnnex ww seeker)
|
2020-05-28 19:55:17 +00:00
|
|
|
=<< workTreeItems ww (getFiles o)
|
2020-07-22 18:23:28 +00:00
|
|
|
Batch fmt -> batchAnnexedFilesMatching fmt seeker
|
2020-05-28 19:55:17 +00:00
|
|
|
where
|
|
|
|
ww = WarnUnmatchLsFiles
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
start :: GetOptions -> Maybe Remote -> SeekInput -> RawFilePath -> Key -> CommandStart
|
|
|
|
start o from si file key = start' expensivecheck from key afile ai si
|
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
|
2019-12-04 17:15:34 +00:00
|
|
|
| autoMode o = numCopiesCheck (fromRawFilePath file) key (<)
|
2017-03-10 17:12:24 +00:00
|
|
|
<||> wantGet False (Just key) afile
|
2015-03-25 21:06:14 +00:00
|
|
|
| otherwise = return True
|
2013-07-03 17:55:50 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
startKeys :: Maybe Remote -> (SeekInput, Key, ActionItem) -> CommandStart
|
|
|
|
startKeys from (si, key, ai) = checkFailedTransferDirection ai Download $
|
|
|
|
start' (return True) from key (AssociatedFile Nothing) ai si
|
2013-07-03 17:55:50 +00:00
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
start' :: Annex Bool -> Maybe Remote -> Key -> AssociatedFile -> ActionItem -> SeekInput -> CommandStart
|
|
|
|
start' expensivecheck from key afile ai si =
|
2020-07-22 18:29:30 +00:00
|
|
|
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
|
2020-09-14 20:49:33 +00:00
|
|
|
go = starting "get" (OnlyActionOn key ai) si
|
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
|
2020-05-14 18:19:28 +00:00
|
|
|
Remote.verifiedAction (Remote.retrieveKeyFile r key afile dest p)
|
2017-10-17 21:54:38 +00:00
|
|
|
) witness
|