change retrieveExportWithContentIdentifier to take a list of ContentIdentifier

This partly fixes an issue where there are duplicate files in the
special remote, and the first file gets swapped with another duplicate,
or deleted. The swap case is fixed by this, the deleted case will need
other changes.

This makes retrieveExportWithContentIdentifier take a list of allowed
ContentIdentifier, same as storeExportWithContentIdentifier,
removeExportWithContentIdentifier, and
checkPresentExportWithContentIdentifier.

Of the special remotes that support importtree, borg is a special case
and does not use content identifiers, S3 I assume can't get mixed up
like this, directory certainly has the problem, and adb also appears to
have had the problem.

Sponsored-by: Graham Spencer on Patreon
This commit is contained in:
Joey Hess 2022-09-20 13:15:31 -04:00
parent 3adf1f24e2
commit 0ffc59d341
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 32 additions and 29 deletions

View file

@ -359,14 +359,15 @@ adjustExportImport' isexport isimport r rs = do
, giveup $ "exported content cannot be verified due to using the " ++ decodeBS (formatKeyVariety (fromKey keyVariety k)) ++ " backend"
)
retrieveKeyFileFromImport dbv ciddbv k af dest p =
getkeycids ciddbv k >>= \case
(cid:_) -> do
retrieveKeyFileFromImport dbv ciddbv k af dest p = do
cids <- getkeycids ciddbv k
if not (null cids)
then do
l <- getfirstexportloc dbv k
snd <$> retrieveExportWithContentIdentifier (importActions r) l cid dest (Left k) p
snd <$> retrieveExportWithContentIdentifier (importActions r) l cids dest (Left k) p
-- In case a content identifier is somehow missing,
-- try this instead.
[] -> if isexport
else if isexport
then retrieveKeyFileFromExport dbv k af dest p
else giveup "no content identifier is recorded, unable to retrieve"