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
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Get where
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2010-11-02 23:04:24 +00:00
|
|
|
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
|
2015-07-10 17:18:46 +00:00
|
|
|
cmd = withGlobalOptions (jobsOption : annexedMatchingOptions) $
|
|
|
|
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
|
|
|
|
}
|
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
|
|
|
|
<*> optional parseFromOption
|
|
|
|
<*> parseAutoOption
|
|
|
|
<*> optional (parseKeyOptions True)
|
|
|
|
|
|
|
|
seek :: GetOptions -> CommandSeek
|
|
|
|
seek o = do
|
|
|
|
from <- maybe (pure Nothing) (Just <$$> getParsed) (getFrom o)
|
|
|
|
withKeyOptions (keyOptions o) (autoMode o)
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
(startKeys from)
|
2015-07-09 20:05:45 +00:00
|
|
|
(withFilesInGit $ whenAnnexed $ start o from)
|
|
|
|
(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
|
|
|
|
start o from file key = start' expensivecheck from key (Just file)
|
2013-07-03 17:55:50 +00:00
|
|
|
where
|
2015-03-25 21:06:14 +00:00
|
|
|
expensivecheck
|
2015-07-09 20:05:45 +00:00
|
|
|
| autoMode o = numCopiesCheck file key (<) <||> wantGet False (Just key) (Just file)
|
2015-03-25 21:06:14 +00:00
|
|
|
| otherwise = return True
|
2013-07-03 17:55:50 +00:00
|
|
|
|
2013-07-03 19:26:59 +00:00
|
|
|
startKeys :: Maybe Remote -> Key -> CommandStart
|
|
|
|
startKeys from key = start' (return True) from key Nothing
|
2013-07-03 17:55:50 +00:00
|
|
|
|
|
|
|
start' :: Annex Bool -> Maybe Remote -> Key -> AssociatedFile -> CommandStart
|
|
|
|
start' expensivecheck from key afile = 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) $
|
2013-07-03 17:55:50 +00:00
|
|
|
go $ Command.Move.fromPerform src False key afile
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
go a = do
|
2014-01-26 19:53:01 +00:00
|
|
|
showStart' "get" key afile
|
2012-11-12 05:05:04 +00:00
|
|
|
next a
|
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
|
2014-03-22 14:42:38 +00:00
|
|
|
dispatch remotes = notifyTransfer Download afile $ trycopy remotes remotes
|
|
|
|
trycopy full [] _ = do
|
2012-11-12 05:05:04 +00:00
|
|
|
Remote.showTriedRemotes full
|
2013-01-09 22:53:59 +00:00
|
|
|
showlocs
|
2012-11-12 05:05:04 +00:00
|
|
|
return False
|
2014-03-22 14:42:38 +00:00
|
|
|
trycopy full (r:rs) witness =
|
2012-11-12 05:05:04 +00:00
|
|
|
ifM (probablyPresent r)
|
2014-03-22 14:42:38 +00:00
|
|
|
( docopy r witness <||> trycopy full rs witness
|
|
|
|
, trycopy full rs witness
|
2012-11-12 05:05:04 +00:00
|
|
|
)
|
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
|
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
|
|
|
docopy r witness = getViaTmp (RemoteVerify r) key $ \dest ->
|
|
|
|
download (Remote.uuid r) key afile noRetry noObserver
|
|
|
|
(\p -> do
|
|
|
|
showAction $ "from " ++ Remote.name r
|
|
|
|
Remote.retrieveKeyFile r key afile dest p
|
|
|
|
) witness
|