refactoring
This commit is contained in:
parent
9c2c3002a6
commit
1704b5e327
3 changed files with 25 additions and 14 deletions
12
Backend.hs
12
Backend.hs
|
@ -10,13 +10,14 @@
|
|||
module Backend (
|
||||
builtinList,
|
||||
defaultBackend,
|
||||
defaultHashBackend,
|
||||
hashBackend,
|
||||
genKey,
|
||||
getBackend,
|
||||
chooseBackend,
|
||||
lookupBackendVariety,
|
||||
lookupBuiltinBackendVariety,
|
||||
maybeLookupBackendVariety,
|
||||
unknownBackendVarietyMessage,
|
||||
isStableKey,
|
||||
isCryptographicallySecureKey,
|
||||
isCryptographicallySecure,
|
||||
|
@ -54,6 +55,15 @@ defaultBackend = maybe cache return =<< Annex.getState Annex.backend
|
|||
valid name = not (null name)
|
||||
lookupname = lookupBackendVariety . parseKeyVariety . encodeBS
|
||||
|
||||
{- A hashing backend. Takes git config into account, but
|
||||
- guarantees the backend is cryptographically secure. -}
|
||||
hashBackend :: Annex Backend
|
||||
hashBackend = do
|
||||
db <- defaultBackend
|
||||
return $ if isCryptographicallySecure db
|
||||
then db
|
||||
else defaultHashBackend
|
||||
|
||||
{- Generates a key for a file. -}
|
||||
genKey :: KeySource -> MeterUpdate -> Backend -> Annex (Key, Backend)
|
||||
genKey source meterupdate b = case B.genKey b of
|
||||
|
|
|
@ -56,3 +56,11 @@ generateEquivilantKey b f =
|
|||
, contentLocation = f
|
||||
, inodeCache = Nothing
|
||||
}
|
||||
|
||||
recordVurlKey :: Backend -> OsPath -> Key -> [Key] -> Annex Bool
|
||||
recordVurlKey b f key eks = generateEquivilantKey b f >>= \case
|
||||
Nothing -> return False
|
||||
Just ek -> do
|
||||
unless (ek `elem` eks) $
|
||||
setEquivilantKey key ek
|
||||
return True
|
||||
|
|
|
@ -30,7 +30,7 @@ import Annex.SpecialRemote.Config
|
|||
import Logs.Remote
|
||||
import Logs.EquivilantKeys
|
||||
import Backend
|
||||
import Backend.VURL.Utilities (generateEquivilantKey)
|
||||
import Backend.VURL.Utilities (recordVurlKey)
|
||||
|
||||
import qualified Data.Map as M
|
||||
|
||||
|
@ -169,18 +169,11 @@ downloadKey urlincludeexclude key _af dest p vc =
|
|||
| otherwise = return (Just v)
|
||||
|
||||
recordvurlkey eks = do
|
||||
-- Make sure to pick a backend that is cryptographically
|
||||
-- secure.
|
||||
db <- defaultBackend
|
||||
let b = if isCryptographicallySecure db
|
||||
then db
|
||||
else defaultHashBackend
|
||||
generateEquivilantKey b dest >>= \case
|
||||
Nothing -> return Nothing
|
||||
Just ek -> do
|
||||
unless (ek `elem` eks) $
|
||||
setEquivilantKey key ek
|
||||
return (Just Verified)
|
||||
b <- hashBackend
|
||||
ifM (recordVurlKey b dest key eks)
|
||||
( return (Just Verified)
|
||||
, return Nothing
|
||||
)
|
||||
|
||||
uploadKey :: Key -> AssociatedFile -> Maybe OsPath -> MeterUpdate -> Annex ()
|
||||
uploadKey _ _ _ _ = giveup "upload to web not supported"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue