implement VURL to URL migration

Just for completeness, someone might want to downgrade I guess?
This commit is contained in:
Joey Hess 2024-03-01 17:01:27 -04:00
parent 9e3ebc0c59
commit b4811b74b1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 11 additions and 4 deletions

View file

@ -17,6 +17,7 @@ import Logs.EquivilantKeys
import Backend.Variety
import Backend.Hash (descChecksum)
import Utility.Hash
import Backend.VURL.Utilities
backends :: [Backend]
backends = [backendVURL]
@ -69,7 +70,7 @@ backendVURL = Backend
, descIncrementalVerifier = descChecksum
}
, canUpgradeKey = Nothing
, fastMigrate = Nothing
, fastMigrate = Just migrateFromVURLToURL
-- Even if a hash is recorded on initial download from the web and
-- is used to verify every subsequent transfer including other
-- downloads from the web, in a split-brain situation there

View file

@ -27,14 +27,20 @@ migrateFromURLToVURL oldkey newbackend _af inannex
Just ek -> do
setEquivilantKey newkey ek
return (Just newkey)
| otherwise = do
liftIO $ print ("migrateFromURL", inannex, fromKey keyVariety oldkey)
return Nothing
| otherwise = return Nothing
where
-- Relies on the first hash being cryptographically secure, and the
-- default hash used by git-annex.
hashbackend = Prelude.head Backend.Hash.backends
migrateFromVURLToURL :: Key -> Backend -> AssociatedFile -> Bool -> Annex (Maybe Key)
migrateFromVURLToURL oldkey newbackend _af _
| fromKey keyVariety oldkey == VURLKey && backendVariety newbackend == URLKey =
return $ Just $ mkKey $ const $
(keyData oldkey)
{ keyVariety = URLKey }
| otherwise = return Nothing
-- The Backend must use a cryptographically secure hash.
generateEquivilantKey :: Backend -> RawFilePath -> Annex (Maybe Key)
generateEquivilantKey b f =