2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- 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
|
2011-06-09 22:54:49 +00:00
|
|
|
import qualified Command.Move
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2011-10-29 19:19:05 +00:00
|
|
|
def :: [Command]
|
more command-specific options
Made --from and --to command-specific options.
Added generic storage for values of command-specific options,
which allows removing some of the special case fields in AnnexState.
(Also added generic storage for command-specific flags, although there are
not yet any.)
Note that this storage uses a Map, so repeatedly looking up the same value
is slightly more expensive than looking up an AnnexState field. But, the
value can be looked up once in the seek stage, transformed as necessary,
and passed in a closure to the start stage, and this avoids that overhead.
Still, I'm hesitant to use this for things like force or fast flags.
It's probably best to reserve it for flags that are only used by a few
commands, or options like --from and --to that it's important only be
allowed to be used with commands that implement them, to avoid user
confusion.
2012-01-06 07:06:25 +00:00
|
|
|
def = [withOptions [Command.Move.fromOption] $ command "get" paramPaths seek
|
2011-10-29 19:19:05 +00:00
|
|
|
"make content of annexed files available"]
|
2010-12-30 19:06:26 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2012-01-06 14:14:37 +00:00
|
|
|
seek = [withField Command.Move.fromOption Remote.byName $ \from ->
|
2012-02-14 03:42:44 +00:00
|
|
|
withFilesInGit $ whenAnnexed $ start from]
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2012-02-14 03:42:44 +00:00
|
|
|
start :: Maybe Remote -> FilePath -> (Key, Backend) -> CommandStart
|
|
|
|
start from file (key, _) = stopUnless (not <$> inAnnex key) $
|
2012-02-16 04:41:30 +00:00
|
|
|
autoCopies file key (<) $ \_numcopies ->
|
2011-12-09 16:23:45 +00:00
|
|
|
case from of
|
|
|
|
Nothing -> go $ perform key
|
2012-01-06 08:02:35 +00:00
|
|
|
Just src -> do
|
2011-12-09 16:23:45 +00:00
|
|
|
-- get --from = copy --from
|
|
|
|
stopUnless (Command.Move.fromOk src key) $
|
|
|
|
go $ Command.Move.fromPerform src False key
|
2011-11-18 21:09:10 +00:00
|
|
|
where
|
|
|
|
go a = do
|
|
|
|
showStart "get" file
|
|
|
|
next a
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2011-07-05 22:31:46 +00:00
|
|
|
perform :: Key -> CommandPerform
|
2012-02-16 04:41:30 +00:00
|
|
|
perform key = stopUnless (getViaTmp key $ getKeyFile key) $
|
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. -}
|
|
|
|
getKeyFile :: Key -> FilePath -> Annex Bool
|
2012-03-14 21:43:34 +00:00
|
|
|
getKeyFile key file = dispatch =<< Remote.keyPossibilities key
|
|
|
|
where
|
|
|
|
dispatch [] = do
|
2011-07-05 22:31:46 +00:00
|
|
|
showNote "not available"
|
|
|
|
Remote.showLocations key []
|
|
|
|
return False
|
2012-03-14 21:43:34 +00:00
|
|
|
dispatch remotes = trycopy remotes remotes
|
2011-07-05 22:31:46 +00:00
|
|
|
trycopy full [] = do
|
|
|
|
Remote.showTriedRemotes full
|
|
|
|
Remote.showLocations key []
|
|
|
|
return False
|
2012-03-14 21:43:34 +00:00
|
|
|
trycopy full (r:rs) =
|
|
|
|
ifM (probablyPresent r)
|
|
|
|
( docopy r (trycopy full rs)
|
|
|
|
, trycopy full rs
|
|
|
|
)
|
2011-07-05 22:31:46 +00:00
|
|
|
-- This check is to avoid an ugly message if a remote is a
|
|
|
|
-- drive that is not mounted.
|
2012-03-14 21:43:34 +00:00
|
|
|
probablyPresent r
|
|
|
|
| Remote.hasKeyCheap r =
|
|
|
|
either (const False) id <$> Remote.hasKey r key
|
|
|
|
| otherwise = return True
|
2011-07-05 22:31:46 +00:00
|
|
|
docopy r continue = do
|
2011-07-19 18:07:23 +00:00
|
|
|
showAction $ "from " ++ Remote.name r
|
2012-03-14 21:43:34 +00:00
|
|
|
ifM (Remote.retrieveKeyFile r key file)
|
|
|
|
( return True , continue)
|