2013-08-20 15:46:35 -04:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 12:50:09 -04:00
|
|
|
- Copyright 2013 Joey Hess <id@joeyh.name>
|
2013-08-20 15:46:35 -04:00
|
|
|
-
|
2019-03-13 15:48:14 -04:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-08-20 15:46:35 -04:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Mirror where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Command.Move
|
|
|
|
import qualified Command.Drop
|
|
|
|
import qualified Command.Get
|
|
|
|
import qualified Remote
|
|
|
|
import Annex.Content
|
2015-04-30 14:02:56 -04:00
|
|
|
import Annex.NumCopies
|
2016-08-03 12:37:12 -04:00
|
|
|
import Types.Transfer
|
2013-08-20 15:46:35 -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-08 15:08:02 -04:00
|
|
|
command "mirror" SectionCommon
|
|
|
|
"mirror content of files to/from another repository"
|
2015-07-10 21:05:34 -04:00
|
|
|
paramPaths (seek <--< optParser)
|
2015-03-25 17:06:14 -04:00
|
|
|
|
2015-07-10 21:05:34 -04:00
|
|
|
data MirrorOptions = MirrorOptions
|
|
|
|
{ mirrorFiles :: CmdParams
|
|
|
|
, fromToOptions :: FromToOptions
|
|
|
|
, keyOptions :: Maybe KeyOptions
|
|
|
|
}
|
2013-08-20 15:46:35 -04:00
|
|
|
|
2015-07-10 21:05:34 -04:00
|
|
|
optParser :: CmdParamsDesc -> Parser MirrorOptions
|
|
|
|
optParser desc = MirrorOptions
|
|
|
|
<$> cmdParams desc
|
|
|
|
<*> parseFromToOptions
|
2016-08-03 12:37:12 -04:00
|
|
|
<*> optional (parseKeyOptions <|> parseFailedTransfersOption)
|
2013-08-20 15:46:35 -04:00
|
|
|
|
2015-07-10 21:05:34 -04:00
|
|
|
instance DeferredParseClass MirrorOptions where
|
|
|
|
finishParse v = MirrorOptions
|
|
|
|
<$> pure (mirrorFiles v)
|
|
|
|
<*> finishParse (fromToOptions v)
|
|
|
|
<*> pure (keyOptions v)
|
2014-01-01 17:39:33 -04:00
|
|
|
|
2015-07-10 21:05:34 -04:00
|
|
|
seek :: MirrorOptions -> CommandSeek
|
2020-05-26 11:55:50 -04:00
|
|
|
seek o = startConcurrency stages $
|
2020-07-24 12:05:28 -04:00
|
|
|
withKeyOptions (keyOptions o) False seeker
|
2018-10-01 14:12:06 -04:00
|
|
|
(commandAction . startKey o (AssociatedFile Nothing))
|
2020-07-13 17:04:02 -04:00
|
|
|
(withFilesInGitAnnex ww seeker)
|
2020-05-28 15:55:17 -04:00
|
|
|
=<< workTreeItems ww (mirrorFiles o)
|
2020-05-26 11:55:50 -04:00
|
|
|
where
|
|
|
|
stages = case fromToOptions o of
|
2023-01-24 13:45:01 -04:00
|
|
|
FromRemote _ -> transferStages
|
2020-05-26 11:55:50 -04:00
|
|
|
ToRemote _ -> commandStages
|
2023-04-25 19:26:20 -04:00
|
|
|
ww = WarnUnmatchLsFiles "mirror"
|
2020-07-13 17:04:02 -04:00
|
|
|
seeker = AnnexedFileSeeker
|
2023-12-06 13:04:32 -04:00
|
|
|
{ startAction = const $ start o
|
2020-07-13 17:04:02 -04:00
|
|
|
, checkContentPresent = Nothing
|
2020-07-24 12:58:23 -04:00
|
|
|
, usesLocationLog = True
|
2020-07-13 17:04:02 -04:00
|
|
|
}
|
2015-07-10 21:05:34 -04:00
|
|
|
|
2020-09-14 16:49:33 -04:00
|
|
|
start :: MirrorOptions -> SeekInput -> RawFilePath -> Key -> CommandStart
|
|
|
|
start o si file k = startKey o afile (si, k, ai)
|
2016-07-20 15:22:55 -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 (k, afile)
|
2015-07-10 21:05:34 -04:00
|
|
|
|
2020-09-14 16:49:33 -04:00
|
|
|
startKey :: MirrorOptions -> AssociatedFile -> (SeekInput, Key, ActionItem) -> CommandStart
|
|
|
|
startKey o afile (si, key, ai) = case fromToOptions o of
|
2016-08-03 12:37:12 -04:00
|
|
|
ToRemote r -> checkFailedTransferDirection ai Upload $ ifM (inAnnex key)
|
2020-09-14 16:49:33 -04:00
|
|
|
( Command.Move.toStart Command.Move.RemoveNever afile key ai si =<< getParsed r
|
2014-01-21 17:08:49 -04:00
|
|
|
, do
|
2021-06-15 11:38:44 -04:00
|
|
|
(numcopies, mincopies) <- getSafestNumMinCopies afile key
|
2021-06-25 15:22:05 -04:00
|
|
|
Command.Drop.startRemote pcc afile ai si numcopies mincopies key (Command.Drop.DroppingUnused False)
|
|
|
|
=<< getParsed r
|
2013-08-20 15:46:35 -04:00
|
|
|
)
|
2016-08-03 12:37:12 -04:00
|
|
|
FromRemote r -> checkFailedTransferDirection ai Download $ do
|
2015-07-10 21:05:34 -04:00
|
|
|
haskey <- flip Remote.hasKey key =<< getParsed r
|
2013-08-20 15:46:35 -04:00
|
|
|
case haskey of
|
|
|
|
Left _ -> stop
|
2020-07-22 14:29:30 -04:00
|
|
|
Right True -> ifM (inAnnex key)
|
|
|
|
( stop
|
2020-09-14 16:49:33 -04:00
|
|
|
, Command.Get.start' (return True) Nothing key afile ai si
|
2020-07-22 14:29:30 -04:00
|
|
|
)
|
2013-08-20 15:46:35 -04:00
|
|
|
Right False -> ifM (inAnnex key)
|
2014-01-21 17:08:49 -04:00
|
|
|
( do
|
2021-06-15 11:38:44 -04:00
|
|
|
(numcopies, mincopies) <- getSafestNumMinCopies afile key
|
2021-06-25 15:22:05 -04:00
|
|
|
Command.Drop.startLocal pcc afile ai si numcopies mincopies key [] (Command.Drop.DroppingUnused False)
|
2013-08-20 15:46:35 -04:00
|
|
|
, stop
|
|
|
|
)
|
2015-07-10 21:05:34 -04:00
|
|
|
where
|
2021-05-25 10:57:06 -04:00
|
|
|
pcc = Command.Drop.PreferredContentChecked False
|