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.
This commit is contained in:
parent
aad8cfe718
commit
13bbb61a51
5 changed files with 18 additions and 1 deletions
|
@ -14,7 +14,8 @@ module Backend (
|
||||||
isAnnexLink,
|
isAnnexLink,
|
||||||
chooseBackend,
|
chooseBackend,
|
||||||
lookupBackendName,
|
lookupBackendName,
|
||||||
maybeLookupBackendName
|
maybeLookupBackendName,
|
||||||
|
checkStableKey,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
|
@ -124,3 +125,7 @@ maybeLookupBackendName s = M.lookup s nameMap
|
||||||
|
|
||||||
nameMap :: M.Map String Backend
|
nameMap :: M.Map String Backend
|
||||||
nameMap = M.fromList $ zip (map B.name list) list
|
nameMap = M.fromList $ zip (map B.name list) list
|
||||||
|
|
||||||
|
checkStableKey :: Key -> Bool
|
||||||
|
checkStableKey k = maybe False (`B.isStableKey` k)
|
||||||
|
(maybeLookupBackendName (keyBackendName k))
|
||||||
|
|
|
@ -45,6 +45,7 @@ genBackend hash = Just Backend
|
||||||
, fsckKey = Just $ checkKeyChecksum hash
|
, fsckKey = Just $ checkKeyChecksum hash
|
||||||
, canUpgradeKey = Just needsUpgrade
|
, canUpgradeKey = Just needsUpgrade
|
||||||
, fastMigrate = Just trivialMigrate
|
, fastMigrate = Just trivialMigrate
|
||||||
|
, isStableKey = const True
|
||||||
}
|
}
|
||||||
|
|
||||||
genBackendE :: Hash -> Maybe Backend
|
genBackendE :: Hash -> Maybe Backend
|
||||||
|
|
|
@ -25,6 +25,9 @@ backend = Backend
|
||||||
, fsckKey = Nothing
|
, fsckKey = Nothing
|
||||||
, canUpgradeKey = Nothing
|
, canUpgradeKey = Nothing
|
||||||
, fastMigrate = 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. -}
|
{- Every unique url has a corresponding key. -}
|
||||||
|
|
|
@ -23,6 +23,7 @@ backend = Backend
|
||||||
, fsckKey = Nothing
|
, fsckKey = Nothing
|
||||||
, canUpgradeKey = Nothing
|
, canUpgradeKey = Nothing
|
||||||
, fastMigrate = Nothing
|
, fastMigrate = Nothing
|
||||||
|
, isStableKey = const True
|
||||||
}
|
}
|
||||||
|
|
||||||
{- The key includes the file size, modification time, and the
|
{- The key includes the file size, modification time, and the
|
||||||
|
|
|
@ -15,9 +15,16 @@ import Types.KeySource
|
||||||
data BackendA a = Backend
|
data BackendA a = Backend
|
||||||
{ name :: String
|
{ name :: String
|
||||||
, getKey :: KeySource -> a (Maybe Key)
|
, getKey :: KeySource -> a (Maybe Key)
|
||||||
|
-- Checks the content of a key.
|
||||||
, fsckKey :: Maybe (Key -> FilePath -> a Bool)
|
, fsckKey :: Maybe (Key -> FilePath -> a Bool)
|
||||||
|
-- Checks if a key can be upgraded to a better form.
|
||||||
, canUpgradeKey :: Maybe (Key -> Bool)
|
, 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)
|
, 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
|
instance Show (BackendA a) where
|
||||||
|
|
Loading…
Reference in a new issue