a few more field functions

This commit is contained in:
Joey Hess 2020-01-15 11:30:45 -04:00
parent 2edf0506a5
commit 6a982e38eb
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 15 additions and 10 deletions

View file

@ -24,13 +24,12 @@ import Utility.DataUnits
import Utility.CopyFile import Utility.CopyFile
import Types.Messages import Types.Messages
import Types.Export import Types.Export
import Types.ProposedAccepted
import Types.Crypto import Types.Crypto
import Types.RemoteConfig import Types.RemoteConfig
import Annex.SpecialRemote.Config (exportTreeField) import Annex.SpecialRemote.Config (exportTreeField)
import Remote.Helper.ExportImport import Remote.Helper.ExportImport
import Remote.Helper.Chunked import Remote.Helper.Chunked
import Remote.Helper.Encryptable (describeEncryption) import Remote.Helper.Encryptable (describeEncryption, encryptionField, highRandomQualityField)
import Git.Types import Git.Types
import Test.Tasty import Test.Tasty
@ -124,17 +123,17 @@ perform rs unavailrs exportr ks = do
adjustChunkSize :: Remote -> Int -> Annex (Maybe Remote) adjustChunkSize :: Remote -> Int -> Annex (Maybe Remote)
adjustChunkSize r chunksize = adjustRemoteConfig r adjustChunkSize r chunksize = adjustRemoteConfig r
(M.insert (Proposed "chunk") (RemoteConfigValue (show chunksize))) (M.insert chunkField (RemoteConfigValue (show chunksize)))
-- Variants of a remote with no encryption, and with simple shared -- Variants of a remote with no encryption, and with simple shared
-- encryption. Gpg key based encryption is not tested. -- encryption. Gpg key based encryption is not tested.
encryptionVariants :: Remote -> Annex [Remote] encryptionVariants :: Remote -> Annex [Remote]
encryptionVariants r = do encryptionVariants r = do
noenc <- adjustRemoteConfig r $ noenc <- adjustRemoteConfig r $
M.insert (Proposed "encryption") (RemoteConfigValue NoneEncryption) M.insert encryptionField (RemoteConfigValue NoneEncryption)
sharedenc <- adjustRemoteConfig r $ sharedenc <- adjustRemoteConfig r $
M.insert (Proposed "encryption") (RemoteConfigValue SharedEncryption) . M.insert encryptionField (RemoteConfigValue SharedEncryption) .
M.insert (Proposed "highRandomQuality") (RemoteConfigValue False) M.insert highRandomQualityField (RemoteConfigValue False)
return $ catMaybes [noenc, sharedenc] return $ catMaybes [noenc, sharedenc]
-- Variant of a remote with exporttree disabled. -- Variant of a remote with exporttree disabled.
@ -146,8 +145,8 @@ disableExportTree r = maybe (error "failed disabling exportree") return
exportTreeVariant :: Remote -> Annex (Maybe Remote) exportTreeVariant :: Remote -> Annex (Maybe Remote)
exportTreeVariant r = ifM (Remote.isExportSupported r) exportTreeVariant r = ifM (Remote.isExportSupported r)
( adjustRemoteConfig r $ ( adjustRemoteConfig r $
M.insert (Proposed "encryption") (RemoteConfigValue NoneEncryption) . M.insert encryptionField (RemoteConfigValue NoneEncryption) .
M.insert (Proposed "exporttree") (RemoteConfigValue True) M.insert exportTreeField (RemoteConfigValue True)
, return Nothing , return Nothing
) )

View file

@ -16,6 +16,7 @@ module Remote.Helper.Chunked (
removeChunks, removeChunks,
retrieveChunks, retrieveChunks,
checkPresentChunks, checkPresentChunks,
chunkField,
) where ) where
import Annex.Common import Annex.Common

View file

@ -21,6 +21,8 @@ module Remote.Helper.Encryptable (
extractCipher, extractCipher,
isEncrypted, isEncrypted,
describeEncryption, describeEncryption,
encryptionField,
highRandomQualityField
) where ) where
import qualified Data.Map as M import qualified Data.Map as M
@ -62,9 +64,12 @@ encryptionConfigParsers =
, optionalStringParser (Accepted "keyid") , optionalStringParser (Accepted "keyid")
, optionalStringParser (Accepted "keyid+") , optionalStringParser (Accepted "keyid+")
, optionalStringParser (Accepted "keyid-") , optionalStringParser (Accepted "keyid-")
, (Accepted "highRandomQuality", \v _c -> Just . RemoteConfigValue <$> parseHighRandomQuality (fmap fromProposedAccepted v)) , (highRandomQualityField, \v _c -> Just . RemoteConfigValue <$> parseHighRandomQuality (fmap fromProposedAccepted v))
] ]
highRandomQualityField :: RemoteConfigField
highRandomQualityField = Accepted "highRandomQuality"
encryptionConfigs :: S.Set RemoteConfigField encryptionConfigs :: S.Set RemoteConfigField
encryptionConfigs = S.fromList (map fst encryptionConfigParsers) encryptionConfigs = S.fromList (map fst encryptionConfigParsers)
@ -151,7 +156,7 @@ encryptionSetup c gc = do
return (storeCipher cipher c', EncryptionIsSetup) return (storeCipher cipher c', EncryptionIsSetup)
highRandomQuality = ifM (Annex.getState Annex.fast) highRandomQuality = ifM (Annex.getState Annex.fast)
( return False ( return False
, case parseHighRandomQuality (fromProposedAccepted <$> M.lookup (Accepted "highRandomQuality") c) of , case parseHighRandomQuality (fromProposedAccepted <$> M.lookup highRandomQualityField c) of
Left err -> giveup err Left err -> giveup err
Right v -> return v Right v -> return v
) )