avoid double checksum when downloading VURL from web for 1st time

Sponsored-by: Jack Hill on Patreon
This commit is contained in:
Joey Hess 2024-03-01 13:44:40 -04:00
parent 4046f17ca0
commit 1b0de3021a
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 23 additions and 25 deletions

View file

@ -147,27 +147,28 @@ downloadKey urlincludeexclude key _af dest p vc =
) )
postdl v@Verified = return (Just v) postdl v@Verified = return (Just v)
postdl v = do postdl v
when (fromKey keyVariety key == VURLKey) $ -- For a VURL key that was not verified on download,
recordvurlkey -- need to generate a hashed key for the content downloaded
return (Just v) -- from the web, and record it for later use verifying this
-- content.
--
-- But when the VURL key has a known size, and already has a
-- recorded hashed key, don't record a new key, since the
-- content on the web is expected to be stable for such a key.
| fromKey keyVariety key == VURLKey =
case fromKey keySize key of
Nothing ->
getEquivilantKeys key
>>= recordvurlkey
Just _ -> do
eks <- getEquivilantKeys key
if null eks
then recordvurlkey eks
else return (Just v)
| otherwise = return (Just v)
-- For a VURL key that was not verified on download, recordvurlkey eks = do
-- need to generate a hashed key for the content downloaded
-- from the web, and record it for later use verifying this content.
--
-- But when the VURL key has a known size, and already has a
-- recorded hashed key, don't record a new key, since the content
-- on the web is expected to be stable for such a key.
recordvurlkey = case fromKey keySize key of
Nothing -> recordvurlkey' =<< getEquivilantKeys key
Just _ -> do
eks <- getEquivilantKeys key
if null eks
then recordvurlkey' eks
else return ()
recordvurlkey' eks = do
-- Make sure to pick a backend that is cryptographically -- Make sure to pick a backend that is cryptographically
-- secure. -- secure.
db <- defaultBackend db <- defaultBackend
@ -178,6 +179,7 @@ downloadKey urlincludeexclude key _af dest p vc =
(hashk, _) <- genKey ks nullMeterUpdate b (hashk, _) <- genKey ks nullMeterUpdate b
unless (hashk `elem` eks) $ unless (hashk `elem` eks) $
setEquivilantKey key hashk setEquivilantKey key hashk
return (Just Verified)
where where
ks = KeySource ks = KeySource
{ keyFilename = mempty -- avoid adding any extension { keyFilename = mempty -- avoid adding any extension

View file

@ -11,11 +11,7 @@ verify the content.
The web special remote can hash the content as it's downloading it from the The web special remote can hash the content as it's downloading it from the
web, and record the resulting hash-based key. web, and record the resulting hash-based key.
> Status: Working, but `git-annex addurl --relaxed --verifiable` followed > Status: Working, but it's not yet possible to migrate an URL key to a VURL key. Should be easy
> by `git-annex get` currently does 2 checksums in the get stage; it should
> only do one.
>
> It's not yet possible to migrate an URL key to a VURL key. Should be easy
> to add support for this. --[[Joey]] > to add support for this. --[[Joey]]
## handling upgrades ## handling upgrades