2010-11-02 19:04:24 -04:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2023-01-23 13:45:26 -04:00
|
|
|
- Copyright 2010-2023 Joey Hess <id@joeyh.name>
|
2010-11-02 19:04:24 -04:00
|
|
|
-
|
2019-03-13 15:48:14 -04:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2010-11-02 19:04:24 -04:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Get where
|
|
|
|
|
|
|
|
import Command
|
2011-06-09 18:54:49 -04:00
|
|
|
import qualified Remote
|
2014-03-22 10:42:38 -04:00
|
|
|
import Annex.Transfer
|
2015-04-30 14:02:56 -04:00
|
|
|
import Annex.NumCopies
|
2012-10-08 16:06:56 -04:00
|
|
|
import Annex.Wanted
|
2013-08-20 15:46:35 -04:00
|
|
|
import qualified Command.Move
|
2023-01-23 13:45:26 -04:00
|
|
|
import Logs.Location
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2015-07-08 12:33:27 -04:00
|
|
|
cmd :: Command
|
2022-06-29 13:28:08 -04:00
|
|
|
cmd = withAnnexOptions [jobsOption, jsonOptions, jsonProgressOption, annexedMatchingOptions] $
|
2015-07-10 13:18:46 -04:00
|
|
|
command "get" SectionCommon
|
|
|
|
"make content of annexed files available"
|
|
|
|
paramPaths (seek <$$> optParser)
|
2010-12-30 15:06:26 -04:00
|
|
|
|
2015-07-09 16:05:45 -04:00
|
|
|
data GetOptions = GetOptions
|
|
|
|
{ getFiles :: CmdParams
|
|
|
|
, getFrom :: Maybe (DeferredParse Remote)
|
|
|
|
, autoMode :: Bool
|
|
|
|
, keyOptions :: Maybe KeyOptions
|
2016-07-05 08:56:23 -04:00
|
|
|
, batchOption :: BatchMode
|
2015-07-09 16:05:45 -04:00
|
|
|
}
|
2013-07-03 13:55:50 -04:00
|
|
|
|
2015-07-09 16:05:45 -04:00
|
|
|
optParser :: CmdParamsDesc -> Parser GetOptions
|
|
|
|
optParser desc = GetOptions
|
|
|
|
<$> cmdParams desc
|
2023-04-05 15:46:51 -04:00
|
|
|
<*> optional (mkParseRemoteOption <$> parseFromOption)
|
2015-07-09 16:05:45 -04:00
|
|
|
<*> parseAutoOption
|
2016-08-03 12:37:12 -04:00
|
|
|
<*> optional (parseIncompleteOption <|> parseKeyOptions <|> parseFailedTransfersOption)
|
2021-08-25 14:20:33 -04:00
|
|
|
<*> parseBatchOption True
|
2015-07-09 16:05:45 -04:00
|
|
|
|
|
|
|
seek :: GetOptions -> CommandSeek
|
2023-01-24 13:45:01 -04:00
|
|
|
seek o = startConcurrency transferStages $ do
|
2015-07-09 16:05:45 -04:00
|
|
|
from <- maybe (pure Nothing) (Just <$$> getParsed) (getFrom o)
|
2020-07-13 17:04:02 -04:00
|
|
|
let seeker = AnnexedFileSeeker
|
2023-12-06 13:04:32 -04:00
|
|
|
{ startAction = const $ start o from
|
2020-07-13 17:04:02 -04:00
|
|
|
, checkContentPresent = Just False
|
|
|
|
, usesLocationLog = True
|
|
|
|
}
|
2016-07-05 08:56:23 -04:00
|
|
|
case batchOption o of
|
2020-07-24 12:05:28 -04:00
|
|
|
NoBatch -> withKeyOptions (keyOptions o) (autoMode o) seeker
|
2018-10-01 14:12:06 -04:00
|
|
|
(commandAction . startKeys from)
|
2020-07-13 17:04:02 -04:00
|
|
|
(withFilesInGitAnnex ww seeker)
|
2020-05-28 15:55:17 -04:00
|
|
|
=<< workTreeItems ww (getFiles o)
|
2022-01-26 12:59:55 -04:00
|
|
|
Batch fmt -> batchOnly (keyOptions o) (getFiles o) $
|
|
|
|
batchAnnexed fmt seeker (startKeys from)
|
2020-05-28 15:55:17 -04:00
|
|
|
where
|
2023-04-25 19:26:20 -04:00
|
|
|
ww = WarnUnmatchLsFiles "get"
|
2010-11-11 18:54:52 -04:00
|
|
|
|
2020-09-14 16:49:33 -04:00
|
|
|
start :: GetOptions -> Maybe Remote -> SeekInput -> RawFilePath -> Key -> CommandStart
|
2024-08-24 09:20:58 -04:00
|
|
|
start o from si file key = do
|
|
|
|
lu <- prepareLiveUpdate Nothing key AddingKey
|
|
|
|
start' lu (expensivecheck lu) from key afile ai si
|
2013-07-03 13:55:50 -04:00
|
|
|
where
|
2017-03-10 13:12:24 -04:00
|
|
|
afile = AssociatedFile (Just file)
|
2019-06-06 12:53:24 -04:00
|
|
|
ai = mkActionItem (key, afile)
|
2024-08-24 09:20:58 -04:00
|
|
|
expensivecheck lu
|
2020-11-03 10:11:04 -04:00
|
|
|
| autoMode o = numCopiesCheck file key (<)
|
2024-08-24 09:20:58 -04:00
|
|
|
<||> wantGet lu False (Just key) afile
|
2015-03-25 17:06:14 -04:00
|
|
|
| otherwise = return True
|
2013-07-03 13:55:50 -04:00
|
|
|
|
2020-09-14 16:49:33 -04:00
|
|
|
startKeys :: Maybe Remote -> (SeekInput, Key, ActionItem) -> CommandStart
|
|
|
|
startKeys from (si, key, ai) = checkFailedTransferDirection ai Download $
|
2024-08-24 09:20:58 -04:00
|
|
|
start' NoLiveUpdate (return True) from key (AssociatedFile Nothing) ai si
|
2013-07-03 13:55:50 -04:00
|
|
|
|
2024-08-24 09:20:58 -04:00
|
|
|
start' :: LiveUpdate -> Annex Bool -> Maybe Remote -> Key -> AssociatedFile -> ActionItem -> SeekInput -> CommandStart
|
|
|
|
start' lu expensivecheck from key afile ai si =
|
2020-07-22 14:29:30 -04:00
|
|
|
stopUnless expensivecheck $
|
2011-12-09 12:23:45 -04:00
|
|
|
case from of
|
2024-08-24 09:20:58 -04:00
|
|
|
Nothing -> go $ perform lu key afile
|
2012-06-12 11:32:06 -04:00
|
|
|
Just src ->
|
2011-12-09 12:23:45 -04:00
|
|
|
stopUnless (Command.Move.fromOk src key) $
|
2024-08-24 09:20:58 -04:00
|
|
|
go $ Command.Move.fromPerform lu src Command.Move.RemoveNever key afile
|
2012-11-12 01:05:04 -04:00
|
|
|
where
|
2020-09-14 16:49:33 -04:00
|
|
|
go = starting "get" (OnlyActionOn key ai) si
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2024-08-24 09:20:58 -04:00
|
|
|
perform :: LiveUpdate -> Key -> AssociatedFile -> CommandPerform
|
|
|
|
perform lu key afile = stopUnless (getKey lu key afile) $
|
2011-12-09 12:23:45 -04:00
|
|
|
next $ return True -- no cleanup needed
|
2011-07-05 18:31:46 -04:00
|
|
|
|
|
|
|
{- Try to find a copy of the file in one of the remotes,
|
|
|
|
- and copy it to here. -}
|
2024-08-24 09:20:58 -04:00
|
|
|
getKey :: LiveUpdate -> Key -> AssociatedFile -> Annex Bool
|
|
|
|
getKey lu key afile = getKey' lu key afile
|
2023-11-30 15:11:57 -04:00
|
|
|
=<< Remote.keyPossibilities (Remote.IncludeIgnored False) key
|
2014-01-19 17:35:36 -04:00
|
|
|
|
2024-08-24 09:20:58 -04:00
|
|
|
getKey' :: LiveUpdate -> Key -> AssociatedFile -> [Remote] -> Annex Bool
|
|
|
|
getKey' lu key afile = dispatch
|
2012-11-12 01:05:04 -04:00
|
|
|
where
|
|
|
|
dispatch [] = do
|
2023-04-10 17:03:41 -04:00
|
|
|
showNote (UnquotedString "not available")
|
2021-01-29 15:11:19 -04:00
|
|
|
showlocs []
|
2012-11-12 01:05:04 -04:00
|
|
|
return False
|
2016-09-06 12:42:50 -04:00
|
|
|
dispatch remotes = notifyTransfer Download afile $ \witness -> do
|
|
|
|
ok <- pickRemote remotes $ \r -> ifM (probablyPresent r)
|
|
|
|
( docopy r witness
|
|
|
|
, return False
|
2012-11-12 01:05:04 -04:00
|
|
|
)
|
2016-09-06 12:42:50 -04:00
|
|
|
if ok
|
|
|
|
then return ok
|
|
|
|
else do
|
|
|
|
Remote.showTriedRemotes remotes
|
2021-01-29 15:11:19 -04:00
|
|
|
showlocs (map Remote.uuid remotes)
|
2016-09-06 12:42:50 -04:00
|
|
|
return False
|
2024-06-23 09:28:18 -04:00
|
|
|
showlocs exclude = Remote.showLocations False key
|
|
|
|
(\u -> pure (u `elem` exclude))
|
2013-01-09 18:53:59 -04:00
|
|
|
"No other repository is known to contain the file."
|
2012-11-12 01:05:04 -04: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
|
2020-12-07 14:44:21 -04:00
|
|
|
docopy r witness = do
|
2023-04-10 17:03:41 -04:00
|
|
|
showAction $ UnquotedString $ "from " ++ Remote.name r
|
2024-08-24 09:20:58 -04:00
|
|
|
logStatusAfter lu key $
|
2023-01-23 13:45:26 -04:00
|
|
|
download r key afile stdRetry witness
|