borg: Support importing files that are hard linked in the borg backup

Note that a key with no size field that is hard linked will
result in listImportableContents reporting a file size of 0,
rather than the actual size of the file. One result is that
the progress meter when getting the file will seem to get stuck
at 100%. Another is that the remote's preferred content expression,
if it tries to match against file size, will treat it as an empty file.
I don't see a way to improve the latter behavior, and the former behavior
is a minor enough problem.

This commit was sponsored by Jake Vosloo on Patreon.
This commit is contained in:
Joey Hess 2021-03-26 13:29:34 -04:00
parent 31eb5fddf3
commit f085ae4937
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 42 additions and 15 deletions

View file

@ -47,10 +47,10 @@ fromThirdPartyImportLocation =
-- find only those ImportLocations that are annex object files.
-- All other ImportLocations are ignored.
importKey :: ImportLocation -> ContentIdentifier -> ByteSize -> MeterUpdate -> Annex (Maybe Key)
importKey loc _cid sz _ = return $ importKey' loc sz
importKey loc _cid sz _ = return $ importKey' loc (Just sz)
importKey' :: ImportLocation -> ByteSize -> Maybe Key
importKey' loc sz = case fileKey f of
importKey' :: ImportLocation -> Maybe ByteSize -> Maybe Key
importKey' loc msz = 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
@ -75,11 +75,11 @@ importKey' loc sz = case fileKey f of
-- (eg, wrong data read off disk during backup, or the object
-- was corrupt in the git-annex repo and that bad object got
-- backed up), they can fsck the remote.
| otherwise -> case fromKey keySize k of
Just sz'
| otherwise -> case (msz, fromKey keySize k) of
(Just sz, Just sz')
| sz' == sz -> Just k
| otherwise -> Nothing
Nothing -> Just k
_ -> Just k
Nothing -> Nothing
where
p = fromImportLocation loc