borg: Fix a bug that prevented importing keys of type URL and WORM

Keys stored on the filesystem are mangled by keyFile to avoid problem
chars. So, that mangling has to be reversed when parsing files from a
borg backup back to a key.

The directory special remote also so mangles them. Some other special
remotes do not; eg S3 just serializes the key -- but S3 object names are
not limited to filesystem valid filenames anyway, so a S3 server must
not map them directly to files in any case. It seems unlikely that a
borg backup of some such special remote will get broken by this change.

This commit was sponsored by Graham Spencer on Patreon.
This commit is contained in:
Joey Hess 2021-03-26 11:51:55 -04:00
parent 537f9d9a11
commit 31eb5fddf3
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 13 additions and 3 deletions

View file

@ -583,7 +583,6 @@ keyFile k =
esc '/' = "%"
esc c = S8.singleton c
{- Reverses keyFile, converting a filename fragment (ie, the basename of
- the symlink target) into a key. -}
fileKey :: RawFilePath -> Maybe Key

View file

@ -26,6 +26,7 @@ git-annex (8.20210311) UNRELEASED; urgency=medium
* Sped up git-annex init in a clone of an existing repository.
* Fix build with attoparsec-0.14.
* Improved display of errors when accessing a git http remote fails.
* borg: Fix a bug that prevented importing keys of type URL and WORM.
-- Joey Hess <id@joeyh.name> Fri, 12 Mar 2021 12:06:37 -0400

View file

@ -260,7 +260,7 @@ getImported u = M.unions <$> (mapM go . exportedTreeishes =<< getExport u)
mkcontents archivename ti = do
let f = ThirdPartyPopulated.fromThirdPartyImportLocation $
mkImportLocation $ getTopFilePath $ LsTree.file ti
k <- deserializeKey' (P.takeFileName f)
k <- fileKey (P.takeFileName f)
return
( genImportLocation archivename f
,

View file

@ -50,7 +50,7 @@ importKey :: ImportLocation -> ContentIdentifier -> ByteSize -> MeterUpdate -> A
importKey loc _cid sz _ = return $ importKey' loc sz
importKey' :: ImportLocation -> ByteSize -> Maybe Key
importKey' loc sz = case deserializeKey' f of
importKey' loc sz = case fileKey f of
Just k
-- Annex objects always are in a subdirectory with the same
-- name as the filename. If this is not the case for the file

View file

@ -0,0 +1,10 @@
[[!comment format=mdwn
username="joey"
subject="""comment 3"""
date="2021-03-26T16:05:49Z"
content="""
I've fixed this bug. Note that, git-annex won't re-scan borg archives that
it's already scanned, so you will need to make a new borg backup in order
to add a new archive, and then git-annex will notice the files it missed
before.
"""]]