e7652b0997
This needs the content to be present in order to hash it. But it's not possible for a module used by Backend.URL to call inAnnex because that would entail a dependency loop. So instead, rely on the fact that Command.Migrate calls inAnnex before performing a migration. But, Command.ExamineKey calls fastMigrate and the key may or may not exist, and it's not wanting to actually perform a migration in any case. To handle that, had to add an additional value to fastMigrate to indicate whether the content is inAnnex. Factored generateEquivilantKey out of Remote.Web. Note that migrateFromURLToVURL hardcodes use of the SHA256E backend. It would have been difficult not to, given all the dependency loop issues. But --backend and annex.backend are used to tell git-annex migrate to use VURL in any case, so there's no config knob that the user could expect to configure that. Sponsored-by: Brock Spratlen on Patreon
51 lines
1.6 KiB
Haskell
51 lines
1.6 KiB
Haskell
{- git-annex VURL backend utilities
|
|
-
|
|
- Copyright 2024 Joey Hess <id@joeyh.name>
|
|
-
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
-}
|
|
|
|
module Backend.VURL.Utilities where
|
|
|
|
import Annex.Common
|
|
import Types.Key
|
|
import Types.Backend
|
|
import Types.KeySource
|
|
import Logs.EquivilantKeys
|
|
import qualified Backend.Hash
|
|
import Utility.Metered
|
|
|
|
migrateFromURLToVURL :: Key -> Backend -> AssociatedFile -> Bool -> Annex (Maybe Key)
|
|
migrateFromURLToVURL oldkey newbackend _af inannex
|
|
| inannex && fromKey keyVariety oldkey == URLKey && backendVariety newbackend == VURLKey = do
|
|
let newkey = mkKey $ const $
|
|
(keyData oldkey)
|
|
{ keyVariety = VURLKey }
|
|
contentfile <- calcRepo (gitAnnexLocation oldkey)
|
|
generateEquivilantKey hashbackend contentfile >>= \case
|
|
Nothing -> return Nothing
|
|
Just ek -> do
|
|
setEquivilantKey newkey ek
|
|
return (Just newkey)
|
|
| otherwise = do
|
|
liftIO $ print ("migrateFromURL", inannex, fromKey keyVariety oldkey)
|
|
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
|
|
|
|
-- The Backend must use a cryptographically secure hash.
|
|
generateEquivilantKey :: Backend -> RawFilePath -> Annex (Maybe Key)
|
|
generateEquivilantKey b f =
|
|
case genKey b of
|
|
Just genkey -> do
|
|
showSideAction (UnquotedString Backend.Hash.descChecksum)
|
|
Just <$> genkey source nullMeterUpdate
|
|
Nothing -> return Nothing
|
|
where
|
|
source = KeySource
|
|
{ keyFilename = mempty -- avoid adding any extension
|
|
, contentLocation = f
|
|
, inodeCache = Nothing
|
|
}
|