From 300935948503d671ad91b943787d71dc1f6e421e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 27 Jul 2014 12:33:46 -0400 Subject: add key stability checking interface Needed for resuming from chunks. Url keys are considered not stable. I considered treating url keys with a known size as stable, but just don't feel that is enough information. --- Backend.hs | 7 ++++++- Backend/Hash.hs | 1 + Backend/URL.hs | 3 +++ Backend/WORM.hs | 1 + Types/Backend.hs | 7 +++++++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Backend.hs b/Backend.hs index 245e79ec2..99752c66f 100644 --- a/Backend.hs +++ b/Backend.hs @@ -14,7 +14,8 @@ module Backend ( isAnnexLink, chooseBackend, lookupBackendName, - maybeLookupBackendName + maybeLookupBackendName, + checkStableKey, ) where import Common.Annex @@ -124,3 +125,7 @@ maybeLookupBackendName s = M.lookup s nameMap nameMap :: M.Map String Backend nameMap = M.fromList $ zip (map B.name list) list + +checkStableKey :: Key -> Bool +checkStableKey k = maybe False (`B.isStableKey` k) + (maybeLookupBackendName (keyBackendName k)) diff --git a/Backend/Hash.hs b/Backend/Hash.hs index 3ff496271..91267ed67 100644 --- a/Backend/Hash.hs +++ b/Backend/Hash.hs @@ -45,6 +45,7 @@ genBackend hash = Just Backend , fsckKey = Just $ checkKeyChecksum hash , canUpgradeKey = Just needsUpgrade , fastMigrate = Just trivialMigrate + , isStableKey = const True } genBackendE :: Hash -> Maybe Backend diff --git a/Backend/URL.hs b/Backend/URL.hs index 4233c56bc..2c2988ac0 100644 --- a/Backend/URL.hs +++ b/Backend/URL.hs @@ -25,6 +25,9 @@ backend = Backend , fsckKey = Nothing , canUpgradeKey = Nothing , fastMigrate = Nothing + -- The content of an url can change at any time, so URL keys are + -- not stable. + , isStableKey = const False } {- Every unique url has a corresponding key. -} diff --git a/Backend/WORM.hs b/Backend/WORM.hs index fdeea6f89..c972602ad 100644 --- a/Backend/WORM.hs +++ b/Backend/WORM.hs @@ -23,6 +23,7 @@ backend = Backend , fsckKey = Nothing , canUpgradeKey = Nothing , fastMigrate = Nothing + , isStableKey = const True } {- The key includes the file size, modification time, and the diff --git a/Types/Backend.hs b/Types/Backend.hs index 7eb59b6e2..5c5855bc3 100644 --- a/Types/Backend.hs +++ b/Types/Backend.hs @@ -15,9 +15,16 @@ import Types.KeySource data BackendA a = Backend { name :: String , getKey :: KeySource -> a (Maybe Key) + -- Checks the content of a key. , fsckKey :: Maybe (Key -> FilePath -> a Bool) + -- 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). , fastMigrate :: Maybe (Key -> BackendA a -> Maybe Key) + -- Checks if a key is known (or assumed) to always refer to the + -- same data. + , isStableKey :: Key -> Bool } instance Show (BackendA a) where -- cgit v1.2.3