git-annex/Types/Backend.hs
Joey Hess e7652b0997
implement URL to VURL migration
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
2024-03-01 16:42:02 -04:00

49 lines
1.8 KiB
Haskell

{- git-annex key backend data type
-
- Most things should not need this, using Types instead
-
- Copyright 2010-2024 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Types.Backend where
import Types.Key
import Types.KeySource
import Utility.Metered
import Utility.FileSystemEncoding
import Utility.Hash (IncrementalVerifier)
data BackendA a = Backend
{ backendVariety :: KeyVariety
, genKey :: Maybe (KeySource -> MeterUpdate -> a Key)
-- Verifies the content of a key, stored in a file, using a hash.
-- This does not need to be cryptographically secure.
, verifyKeyContent :: Maybe (Key -> RawFilePath -> a Bool)
-- Incrementally verifies the content of a key, using the same
-- hash as verifyKeyContent, but with the content provided
-- incrementally a piece at a time, until finalized.
, verifyKeyContentIncrementally :: Maybe (Key -> a IncrementalVerifier)
-- Checks if a key can be upgraded to a better form.
, canUpgradeKey :: Maybe (Key -> Bool)
-- Checks if there is a fast way to migrate a key to a different
-- backend (ie, without re-hashing).
-- The Bool is true if the content of the key has been verified to
-- be inAnnex.
, fastMigrate :: Maybe (Key -> BackendA a -> AssociatedFile -> Bool -> a (Maybe Key))
-- Checks if a key is known (or assumed) to always refer to the
-- same data.
, isStableKey :: Key -> Bool
-- Are all keys using this backend verified using a cryptographically
-- secure hash?
, isCryptographicallySecure :: Bool
-- Checks if a key is verified using a cryptographically secure hash.
, isCryptographicallySecureKey :: Key -> a Bool
}
instance Show (BackendA a) where
show backend = "Backend { name =\"" ++ decodeBS (formatKeyVariety (backendVariety backend)) ++ "\" }"
instance Eq (BackendA a) where
a == b = backendVariety a == backendVariety b