converted Mirror
This commit is contained in:
parent
e4b3701dfe
commit
c70c841d30
2 changed files with 36 additions and 29 deletions
|
@ -81,7 +81,7 @@ import qualified Command.Schedule
|
||||||
import qualified Command.Ungroup
|
import qualified Command.Ungroup
|
||||||
import qualified Command.Vicfg
|
import qualified Command.Vicfg
|
||||||
import qualified Command.Sync
|
import qualified Command.Sync
|
||||||
--import qualified Command.Mirror
|
import qualified Command.Mirror
|
||||||
--import qualified Command.AddUrl
|
--import qualified Command.AddUrl
|
||||||
#ifdef WITH_FEED
|
#ifdef WITH_FEED
|
||||||
--import qualified Command.ImportFeed
|
--import qualified Command.ImportFeed
|
||||||
|
@ -130,7 +130,7 @@ cmds =
|
||||||
, Command.Unlock.editcmd
|
, Command.Unlock.editcmd
|
||||||
, Command.Lock.cmd
|
, Command.Lock.cmd
|
||||||
, Command.Sync.cmd
|
, Command.Sync.cmd
|
||||||
-- , Command.Mirror.cmd
|
, Command.Mirror.cmd
|
||||||
-- , Command.AddUrl.cmd
|
-- , Command.AddUrl.cmd
|
||||||
#ifdef WITH_FEED
|
#ifdef WITH_FEED
|
||||||
-- , Command.ImportFeed.cmd
|
-- , Command.ImportFeed.cmd
|
||||||
|
|
|
@ -17,42 +17,48 @@ import Annex.Content
|
||||||
import Annex.NumCopies
|
import Annex.NumCopies
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = withOptions mirrorOptions $
|
cmd = withGlobalOptions ([jobsOption] ++ annexedMatchingOptions) $
|
||||||
command "mirror" SectionCommon
|
command "mirror" SectionCommon
|
||||||
"mirror content of files to/from another repository"
|
"mirror content of files to/from another repository"
|
||||||
paramPaths (withParams seek)
|
paramPaths (seek <--< optParser)
|
||||||
|
|
||||||
mirrorOptions :: [Option]
|
data MirrorOptions = MirrorOptions
|
||||||
mirrorOptions = fromToOptions ++ [jobsOption] ++ annexedMatchingOptions ++ keyOptions
|
{ mirrorFiles :: CmdParams
|
||||||
|
, fromToOptions :: FromToOptions
|
||||||
|
, keyOptions :: Maybe KeyOptions
|
||||||
|
}
|
||||||
|
|
||||||
seek :: CmdParams -> CommandSeek
|
optParser :: CmdParamsDesc -> Parser MirrorOptions
|
||||||
seek ps = do
|
optParser desc = MirrorOptions
|
||||||
to <- getOptionField toOption Remote.byNameWithUUID
|
<$> cmdParams desc
|
||||||
from <- getOptionField fromOption Remote.byNameWithUUID
|
<*> parseFromToOptions
|
||||||
withKeyOptions False
|
<*> optional (parseKeyOptions False)
|
||||||
(startKey to from Nothing)
|
|
||||||
(withFilesInGit $ whenAnnexed $ start to from)
|
|
||||||
ps
|
|
||||||
|
|
||||||
start :: Maybe Remote -> Maybe Remote -> FilePath -> Key -> CommandStart
|
instance DeferredParseClass MirrorOptions where
|
||||||
start to from file = startKey to from (Just file)
|
finishParse v = MirrorOptions
|
||||||
|
<$> pure (mirrorFiles v)
|
||||||
|
<*> finishParse (fromToOptions v)
|
||||||
|
<*> pure (keyOptions v)
|
||||||
|
|
||||||
startKey :: Maybe Remote -> Maybe Remote -> Maybe FilePath -> Key -> CommandStart
|
seek :: MirrorOptions -> CommandSeek
|
||||||
startKey to from afile key =
|
seek o = withKeyOptions (keyOptions o) False
|
||||||
case (from, to) of
|
(startKey o Nothing)
|
||||||
(Nothing, Nothing) -> error "specify either --from or --to"
|
(withFilesInGit $ whenAnnexed $ start o)
|
||||||
(Nothing, Just r) -> mirrorto r
|
(mirrorFiles o)
|
||||||
(Just r, Nothing) -> mirrorfrom r
|
|
||||||
_ -> error "only one of --from or --to can be specified"
|
start :: MirrorOptions -> FilePath -> Key -> CommandStart
|
||||||
where
|
start o file = startKey o (Just file)
|
||||||
mirrorto r = ifM (inAnnex key)
|
|
||||||
( Command.Move.toStart r False afile key
|
startKey :: MirrorOptions -> Maybe FilePath -> Key -> CommandStart
|
||||||
|
startKey o afile key = case fromToOptions o of
|
||||||
|
ToRemote r -> ifM (inAnnex key)
|
||||||
|
( Command.Move.toStart False afile key =<< getParsed r
|
||||||
, do
|
, do
|
||||||
numcopies <- getnumcopies
|
numcopies <- getnumcopies
|
||||||
Command.Drop.startRemote afile numcopies key r
|
Command.Drop.startRemote afile numcopies key =<< getParsed r
|
||||||
)
|
)
|
||||||
mirrorfrom r = do
|
FromRemote r -> do
|
||||||
haskey <- Remote.hasKey r key
|
haskey <- flip Remote.hasKey key =<< getParsed r
|
||||||
case haskey of
|
case haskey of
|
||||||
Left _ -> stop
|
Left _ -> stop
|
||||||
Right True -> Command.Get.start' (return True) Nothing key afile
|
Right True -> Command.Get.start' (return True) Nothing key afile
|
||||||
|
@ -62,4 +68,5 @@ startKey to from afile key =
|
||||||
Command.Drop.startLocal afile numcopies key Nothing
|
Command.Drop.startLocal afile numcopies key Nothing
|
||||||
, stop
|
, stop
|
||||||
)
|
)
|
||||||
|
where
|
||||||
getnumcopies = maybe getNumCopies getFileNumCopies afile
|
getnumcopies = maybe getNumCopies getFileNumCopies afile
|
||||||
|
|
Loading…
Add table
Reference in a new issue