2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2013-07-03 17:55:50 +00:00
|
|
|
- Copyright 2010, 2013 Joey Hess <joey@kitenet.net>
|
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
|
2012-07-01 19:18:36 +00:00
|
|
|
import Logs.Transfer
|
2012-10-08 20:06:56 +00:00
|
|
|
import Annex.Wanted
|
2013-07-03 17:55:50 +00:00
|
|
|
import GitAnnex.Options
|
2013-08-20 19:46:35 +00:00
|
|
|
import qualified Command.Move
|
2013-07-03 17:55:50 +00:00
|
|
|
import Types.Key
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2011-10-29 19:19:05 +00:00
|
|
|
def :: [Command]
|
2013-07-03 17:55:50 +00:00
|
|
|
def = [withOptions getOptions $ command "get" paramPaths seek
|
2013-03-24 22:28:21 +00:00
|
|
|
SectionCommon "make content of annexed files available"]
|
2010-12-30 19:06:26 +00:00
|
|
|
|
2013-07-03 17:55:50 +00:00
|
|
|
getOptions :: [Option]
|
2013-08-20 19:46:35 +00:00
|
|
|
getOptions = fromOption : keyOptions
|
2013-07-03 17:55:50 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2013-07-03 17:55:50 +00:00
|
|
|
seek =
|
2013-08-20 19:46:35 +00:00
|
|
|
[ withField fromOption Remote.byNameWithUUID $ \from ->
|
2013-07-03 19:26:59 +00:00
|
|
|
withKeyOptions (startKeys from) $
|
2013-07-03 17:55:50 +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
|
2013-07-03 17:55:50 +00:00
|
|
|
start from file (key, _) = start' expensivecheck from key (Just file)
|
|
|
|
where
|
|
|
|
expensivecheck = checkAuto (numCopiesCheck file key (<) <||> wantGet False (Just file))
|
|
|
|
|
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
|
2013-07-03 17:55:50 +00:00
|
|
|
go a = do
|
|
|
|
showStart "get" (fromMaybe (key2file 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
|
|
|
|
perform key afile = stopUnless (getViaTmp key $ getKeyFile 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. -}
|
2013-07-03 17:55:50 +00:00
|
|
|
getKeyFile :: Key -> AssociatedFile -> FilePath -> Annex Bool
|
|
|
|
getKeyFile key afile dest = dispatch =<< Remote.keyPossibilities key
|
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
|
|
|
|
dispatch remotes = trycopy remotes remotes
|
|
|
|
trycopy full [] = do
|
|
|
|
Remote.showTriedRemotes full
|
2013-01-09 22:53:59 +00:00
|
|
|
showlocs
|
2012-11-12 05:05:04 +00:00
|
|
|
return False
|
|
|
|
trycopy full (r:rs) =
|
|
|
|
ifM (probablyPresent r)
|
|
|
|
( docopy r (trycopy full rs)
|
|
|
|
, trycopy full rs
|
|
|
|
)
|
2013-01-09 22:53:59 +00:00
|
|
|
showlocs = Remote.showLocations key [] $
|
|
|
|
"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
|
|
|
|
docopy r continue = do
|
2013-07-03 17:55:50 +00:00
|
|
|
ok <- download (Remote.uuid r) key afile noRetry $ \p -> do
|
2012-11-12 05:05:04 +00:00
|
|
|
showAction $ "from " ++ Remote.name r
|
2013-07-03 17:55:50 +00:00
|
|
|
Remote.retrieveKeyFile r key afile dest p
|
2012-11-12 05:05:04 +00:00
|
|
|
if ok then return ok else continue
|