git-annex/BackendTypes.hs

45 lines
1.1 KiB
Haskell
Raw Normal View History

2010-10-14 06:52:17 +00:00
{- git-annex backend data types
-
- Mostly only backend implementations should need to import this.
-}
2010-10-12 19:52:18 +00:00
2010-10-14 06:52:17 +00:00
module BackendTypes where
2010-10-12 19:52:18 +00:00
2010-10-14 01:28:47 +00:00
import Control.Monad.State
2010-10-13 00:04:36 +00:00
import Data.String.Utils
2010-10-14 06:36:41 +00:00
import qualified GitRepo as Git
2010-10-12 19:52:18 +00:00
2010-10-14 06:52:17 +00:00
-- git-annex's runtime state type doesn't really belong here,
-- but it uses Backend, so has to be here to avoid a depends loop.
2010-10-14 01:28:47 +00:00
data AnnexState = AnnexState {
2010-10-14 06:36:41 +00:00
repo :: Git.Repo,
2010-10-12 19:52:18 +00:00
backends :: [Backend]
2010-10-12 20:06:10 +00:00
} deriving (Show)
2010-10-14 01:28:47 +00:00
-- git-annex's monad
type Annex = StateT AnnexState IO
2010-10-12 20:06:10 +00:00
-- annexed filenames are mapped into keys
data Key = Key String deriving (Eq)
-- show a key to convert it to a string
instance Show Key where
show (Key v) = v
2010-10-12 20:06:10 +00:00
-- this structure represents a key/value backend
data Backend = Backend {
-- name of this backend
name :: String,
-- converts a filename to a key
2010-10-14 01:28:47 +00:00
getKey :: FilePath -> Annex (Maybe Key),
2010-10-12 20:06:10 +00:00
-- stores a file's contents to a key
2010-10-14 01:28:47 +00:00
storeFileKey :: FilePath -> Key -> Annex Bool,
2010-10-12 20:06:10 +00:00
-- retrieves a key's contents to a file
2010-10-14 01:28:47 +00:00
retrieveKeyFile :: Key -> FilePath -> Annex Bool,
2010-10-12 20:06:10 +00:00
-- removes a key
2010-10-14 01:28:47 +00:00
removeKey :: Key -> Annex Bool
2010-10-12 19:52:18 +00:00
}
2010-10-12 20:06:10 +00:00
instance Show Backend where
show backend = "Backend { name =\"" ++ (name backend) ++ "\" }"