sync --content: Fix dropping unwanted content from the local repository

This fixes a bug with the numcopies counting when using sync --content.
It did not always pass the local repo uuid to handleDropsFrom, and so the
numcopies counting was off by one, and unwanted local content would only be
dropped when there were numcopies+1 remote copies.

Also, support dropping local content that has reached an
exporttree remote that is not untrusted (currently only S3 remotes
with versioning).
This commit is contained in:
Joey Hess 2018-12-18 13:58:12 -04:00
parent 9438ecc30b
commit 6d381df0e6
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 36 additions and 13 deletions

View file

@ -166,9 +166,9 @@ seek o = allowConcurrentOutput $ do
remotes <- syncRemotes (syncWith o)
let gitremotes = filter Remote.gitSyncableRemote remotes
(exportremotes, dataremotes) <- partition (exportTree . Remote.config)
. filter (\r -> Remote.uuid r /= NoUUID)
dataremotes <- filter (\r -> Remote.uuid r /= NoUUID)
<$> filterM (not <$$> liftIO . getDynamicConfig . remoteAnnexIgnore . Remote.gitconfig) remotes
let exportremotes = filter (exportTree . Remote.config) dataremotes
if cleanupOption o
then do
@ -187,8 +187,11 @@ seek o = allowConcurrentOutput $ do
]
whenM shouldsynccontent $ do
syncedcontent <- withbranch $ seekSyncContent o dataremotes
-- Send content to any exports first, in
-- case that lets content be dropped from
-- other repositories.
exportedcontent <- withbranch $ seekExportContent exportremotes
syncedcontent <- withbranch $ seekSyncContent o dataremotes
-- Transferring content can take a while,
-- and other changes can be pushed to the
-- git-annex branch on the remotes in the
@ -618,14 +621,15 @@ seekSyncContent o rs currbranch = do
-}
syncFile :: Either (Maybe (Bloom Key)) (Key -> Annex ()) -> [Remote] -> AssociatedFile -> Key -> Annex Bool
syncFile ebloom rs af k = onlyActionOn' k $ do
inhere <- inAnnex k
locs <- map Remote.uuid <$> Remote.keyPossibilities k
let (have, lack) = partition (\r -> Remote.uuid r `elem` locs) rs
got <- anyM id =<< handleget have
got <- anyM id =<< handleget have inhere
putrs <- handleput lack
u <- getUUID
let locs' = concat [[u | got], putrs, locs]
let locs' = concat [if inhere || got then [u] else [], putrs, locs]
-- A bloom filter is populated with all the keys in the first pass.
-- On the second pass, avoid dropping keys that were seen in the
@ -649,12 +653,12 @@ syncFile ebloom rs af k = onlyActionOn' k $ do
return (got || not (null putrs))
where
wantget have = allM id
wantget have inhere = allM id
[ pure (not $ null have)
, not <$> inAnnex k
, pure (not inhere)
, wantGet True (Just k) af
]
handleget have = ifM (wantget have)
handleget have inhere = ifM (wantget have inhere)
( return [ get have ]
, return []
)