diff options
Diffstat (limited to 'Types')
-rw-r--r-- | Types/Backend.hs | 7 | ||||
-rw-r--r-- | Types/Command.hs | 2 | ||||
-rw-r--r-- | Types/Key.hs | 15 | ||||
-rw-r--r-- | Types/Remote.hs | 6 | ||||
-rw-r--r-- | Types/StoreRetrieve.hs | 37 |
5 files changed, 65 insertions, 2 deletions
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 diff --git a/Types/Command.hs b/Types/Command.hs index 0df7c82e6..1f8456194 100644 --- a/Types/Command.hs +++ b/Types/Command.hs @@ -69,6 +69,7 @@ data CommandSection | SectionMetaData | SectionUtility | SectionPlumbing + | SectionTesting deriving (Eq, Ord, Enum, Bounded) descSection :: CommandSection -> String @@ -79,3 +80,4 @@ descSection SectionQuery = "Query commands" descSection SectionMetaData = "Metadata commands" descSection SectionUtility = "Utility commands" descSection SectionPlumbing = "Plumbing commands" +descSection SectionTesting = "Testing commands" diff --git a/Types/Key.hs b/Types/Key.hs index 90f66f23e..154e813ff 100644 --- a/Types/Key.hs +++ b/Types/Key.hs @@ -13,6 +13,8 @@ module Types.Key ( stubKey, key2file, file2key, + nonChunkKey, + chunkKeyOffset, prop_idempotent_key_encode, prop_idempotent_key_decode @@ -47,6 +49,19 @@ stubKey = Key , keyChunkNum = Nothing } +-- Gets the parent of a chunk key. +nonChunkKey :: Key -> Key +nonChunkKey k = k + { keyChunkSize = Nothing + , keyChunkNum = Nothing + } + +-- Where a chunk key is offset within its parent. +chunkKeyOffset :: Key -> Maybe Integer +chunkKeyOffset k = (*) + <$> keyChunkSize k + <*> (pred <$> keyChunkNum k) + fieldSep :: Char fieldSep = '-' diff --git a/Types/Remote.hs b/Types/Remote.hs index 2ddb68dfb..805b98474 100644 --- a/Types/Remote.hs +++ b/Types/Remote.hs @@ -56,7 +56,9 @@ data RemoteA a = Remote { name :: RemoteName, -- Remotes have a use cost; higher is more expensive cost :: Cost, - -- Transfers a key to the remote. + -- Transfers a key's contents from disk to the remote. + -- The key should not appear to be present on the remote until + -- all of its contents have been transferred. storeKey :: Key -> AssociatedFile -> MeterUpdate -> a Bool, -- Retrieves a key's contents to a file. -- (The MeterUpdate does not need to be used if it retrieves @@ -64,7 +66,7 @@ data RemoteA a = Remote { retrieveKeyFile :: Key -> AssociatedFile -> FilePath -> MeterUpdate -> a Bool, -- retrieves a key's contents to a tmp file, if it can be done cheaply retrieveKeyFileCheap :: Key -> FilePath -> a Bool, - -- removes a key's contents + -- removes a key's contents (succeeds if the contents are not present) removeKey :: Key -> a Bool, -- Checks if a key is present in the remote; if the remote -- cannot be accessed returns a Left error message. diff --git a/Types/StoreRetrieve.hs b/Types/StoreRetrieve.hs new file mode 100644 index 000000000..33f66efb1 --- /dev/null +++ b/Types/StoreRetrieve.hs @@ -0,0 +1,37 @@ +{- Types for Storer and Retriever actions for remotes. + - + - Copyright 2014 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +{-# LANGUAGE Rank2Types #-} + +module Types.StoreRetrieve where + +import Common.Annex +import Utility.Metered + +import qualified Data.ByteString.Lazy as L + +-- Prepares for and then runs an action that will act on a Key's +-- content, passing it a helper when the preparation is successful. +type Preparer helper = forall a. Key -> (Maybe helper -> Annex a) -> Annex a + +-- A source of a Key's content. +data ContentSource + = FileContent FilePath + | ByteContent L.ByteString + +isByteContent :: ContentSource -> Bool +isByteContent (ByteContent _) = True +isByteContent (FileContent _) = False + +-- Action that stores a Key's content on a remote. +-- Can throw exceptions. +type Storer = Key -> ContentSource -> MeterUpdate -> Annex Bool + +-- Action that retrieves a Key's content from a remote, passing it to a +-- callback. +-- Throws exception if key is not present, or remote is not accessible. +type Retriever = Key -> MeterUpdate -> (ContentSource -> Annex Bool) -> Annex Bool |