make sync --content get from third-party populated remotes like borg

This commit is contained in:
Joey Hess 2020-12-23 12:10:39 -04:00
parent d239a55bd1
commit 1574972ba9
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 36 additions and 15 deletions

View file

@ -207,13 +207,11 @@ seek' o = do
let withbranch a = a =<< getCurrentBranch let withbranch a = a =<< getCurrentBranch
remotes <- syncRemotes (syncWith o) remotes <- syncRemotes (syncWith o)
-- Remotes that are git repositories, not special remotes.
let gitremotes = filter (Remote.gitSyncableRemoteType . Remote.remotetype) remotes let gitremotes = filter (Remote.gitSyncableRemoteType . Remote.remotetype) remotes
dataremotes <- filter (\r -> Remote.uuid r /= NoUUID) -- Remotes that contain annex object content.
contentremotes <- filter (\r -> Remote.uuid r /= NoUUID)
<$> filterM (not <$$> liftIO . getDynamicConfig . remoteAnnexIgnore . Remote.gitconfig) remotes <$> filterM (not <$$> liftIO . getDynamicConfig . remoteAnnexIgnore . Remote.gitconfig) remotes
let (exportremotes, nonexportremotes) = partition (exportTree . Remote.config) dataremotes
let isimport r = importTree (Remote.config r) || Remote.thirdPartyPopulated (Remote.remotetype r)
let importremotes = filter isimport dataremotes
let keyvalueremotes = filter (not . isimport) nonexportremotes
if cleanupOption o if cleanupOption o
then do then do
@ -233,17 +231,27 @@ seek' o = do
content <- shouldSyncContent o content <- shouldSyncContent o
forM_ importremotes $ forM_ (filter isImport contentremotes) $
withbranch . importRemote content o mergeConfig withbranch . importRemote content o mergeConfig
forM_ (filter isThirdPartyPopulated contentremotes) $
pullThirdPartyPopulated o
when content $ do when content $ do
-- Send content to any exports before other -- Send content to any exports before other
-- repositories, in case that lets content -- repositories, in case that lets content
-- be dropped from other repositories. -- be dropped from other repositories.
exportedcontent <- withbranch $ exportedcontent <- withbranch $
seekExportContent (Just o) exportremotes seekExportContent (Just o)
(filter isExport contentremotes)
-- Sync content with remotes, but not with
-- export or import remotes, which handle content
-- syncing as part of export and import.
syncedcontent <- withbranch $ syncedcontent <- withbranch $
seekSyncContent o keyvalueremotes seekSyncContent o $ filter
(\r -> not (isExport r || isImport r))
contentremotes
-- Transferring content can take a while, -- Transferring content can take a while,
-- and other changes can be pushed to the -- and other changes can be pushed to the
-- git-annex branch on the remotes in the -- git-annex branch on the remotes in the
@ -465,9 +473,6 @@ pullRemote o mergeconfig remote branch = stopUnless (pure $ pullOption o && want
importRemote :: Bool -> SyncOptions -> [Git.Merge.MergeConfig] -> Remote -> CurrBranch -> CommandSeek importRemote :: Bool -> SyncOptions -> [Git.Merge.MergeConfig] -> Remote -> CurrBranch -> CommandSeek
importRemote importcontent o mergeconfig remote currbranch importRemote importcontent o mergeconfig remote currbranch
| not (pullOption o) || not wantpull = noop | not (pullOption o) || not wantpull = noop
| Remote.thirdPartyPopulated (Remote.remotetype remote) =
when (canImportKeys remote importcontent) $
importThirdPartyPopulated remote
| otherwise = case remoteAnnexTrackingBranch (Remote.gitconfig remote) of | otherwise = case remoteAnnexTrackingBranch (Remote.gitconfig remote) of
Nothing -> noop Nothing -> noop
Just tb -> do Just tb -> do
@ -484,15 +489,17 @@ importRemote importcontent o mergeconfig remote currbranch
where where
wantpull = remoteAnnexPull (Remote.gitconfig remote) wantpull = remoteAnnexPull (Remote.gitconfig remote)
{- Import from a remote that is populated by a third party, by listing {- Handle a remote that is populated by a third party, by listing
- the contents of the remote, and then adding only the files on it that - the contents of the remote, and then adding only the files on it that
- importKey identifies to a tree. The tree is only used to keep track - importKey identifies to a tree. The tree is only used to keep track
- of where keys are located on the remote, no remote tracking branch is - of where keys are located on the remote, no remote tracking branch is
- updated, because the filenames are the names of annex object files, - updated, because the filenames are the names of annex object files,
- not suitable for a tracking branch. Does not transfer any content. -} - not suitable for a tracking branch. Does not transfer any content. -}
importThirdPartyPopulated :: Remote -> CommandSeek pullThirdPartyPopulated :: SyncOptions -> Remote -> CommandSeek
importThirdPartyPopulated remote = pullThirdPartyPopulated o remote
void $ includeCommandAction $ starting "list" ai si $ | not (pullOption o) || not wantpull = noop
| not (canImportKeys remote False) = noop
| otherwise = void $ includeCommandAction $ starting "list" ai si $
Command.Import.listContents' remote ImportTree (CheckGitIgnore False) go Command.Import.listContents' remote ImportTree (CheckGitIgnore False) go
where where
go (Just importable) = importKeys remote ImportTree False True importable >>= \case go (Just importable) = importKeys remote ImportTree False True importable >>= \case
@ -507,6 +514,8 @@ importThirdPartyPopulated remote =
ai = ActionItemOther (Just (Remote.name remote)) ai = ActionItemOther (Just (Remote.name remote))
si = SeekInput [] si = SeekInput []
wantpull = remoteAnnexPull (Remote.gitconfig remote)
{- The remote probably has both a master and a synced/master branch. {- The remote probably has both a master and a synced/master branch.
- Which to merge from? Well, the master has whatever latest changes - Which to merge from? Well, the master has whatever latest changes
- were committed (or pushed changes, if this is a bare remote), - were committed (or pushed changes, if this is a bare remote),
@ -806,6 +815,7 @@ syncFile ebloom rs af k = do
wantput r wantput r
| Remote.readonly r || remoteAnnexReadOnly (Remote.gitconfig r) = return False | Remote.readonly r || remoteAnnexReadOnly (Remote.gitconfig r) = return False
| isThirdPartyPopulated r = return False
| otherwise = wantSend True (Just k) af (Remote.uuid r) | otherwise = wantSend True (Just k) af (Remote.uuid r)
handleput lack = catMaybes <$> ifM (inAnnex k) handleput lack = catMaybes <$> ifM (inAnnex k)
( forM lack $ \r -> ( forM lack $ \r ->
@ -918,3 +928,12 @@ onlyAnnex o
| notOnlyAnnexOption o = pure False | notOnlyAnnexOption o = pure False
| onlyAnnexOption o = pure True | onlyAnnexOption o = pure True
| otherwise = getGitConfigVal annexSyncOnlyAnnex | otherwise = getGitConfigVal annexSyncOnlyAnnex
isExport :: Remote -> Bool
isExport = exportTree . Remote.config
isImport :: Remote -> Bool
isImport = importTree . Remote.config
isThirdPartyPopulated :: Remote -> Bool
isThirdPartyPopulated = Remote.thirdPartyPopulated . Remote.remotetype

View file

@ -1,2 +1,4 @@
Subject says it all really, sync does not try to get content Subject says it all really, sync does not try to get content
from remotes that are thirdPartyPopulated yet. from remotes that are thirdPartyPopulated yet.
> [[done]] --[[Joey]]