aboutsummaryrefslogtreecommitdiff
path: root/Backend.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-12 16:06:10 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-12 16:06:10 -0400
commit2ac47a3a59b2b9b8980b4a9d3277bcb653bcb026 (patch)
tree2d40eae24513c5f895a9da771f0b34d228439c97 /Backend.hs
parent759f146d0fd5857cbbb796367c3dd8c695550b46 (diff)
thread State thru to backends
Diffstat (limited to 'Backend.hs')
-rw-r--r--Backend.hs55
1 files changed, 28 insertions, 27 deletions
diff --git a/Backend.hs b/Backend.hs
index 2d3ea42d6..ddfd8b19d 100644
--- a/Backend.hs
+++ b/Backend.hs
@@ -28,74 +28,75 @@ import System.Directory
import Locations
import GitRepo
import Utility
-import BackendType
+import Types
{- Name of state file that holds the key for an annexed file,
- using a given backend. -}
-backendFile :: Backend -> GitRepo -> FilePath -> String
-backendFile backend repo file = gitStateDir repo ++
- (gitRelative repo file) ++ "." ++ (name backend)
+backendFile :: Backend -> State -> FilePath -> String
+backendFile backend state file =
+ gitStateDir (repo state) ++ (gitRelative (repo state) file) ++
+ "." ++ (name backend)
{- Attempts to store a file in one of the backends, and returns
- its key. -}
-storeFile :: [Backend] -> GitRepo -> FilePath -> IO (Maybe Key)
+storeFile :: [Backend] -> State -> FilePath -> IO (Maybe Key)
storeFile [] _ _ = return Nothing
-storeFile (b:bs) repo file = do
- try <- (getKey b) repo (gitRelative repo file)
+storeFile (b:bs) state file = do
+ try <- (getKey b) state (gitRelative (repo state) file)
case (try) of
Nothing -> nextbackend
Just key -> do
- stored <- (storeFileKey b) repo file key
+ stored <- (storeFileKey b) state file key
if (not stored)
then nextbackend
else do
bookkeeping key
return $ Just key
where
- nextbackend = storeFile bs repo file
- backendfile = backendFile b repo file
+ nextbackend = storeFile bs state file
+ backendfile = backendFile b state file
bookkeeping key = do
createDirectoryIfMissing True (parentDir backendfile)
writeFile backendfile key
{- Attempts to retrieve an file from one of the backends, saving it to
- a specified location. -}
-retrieveFile :: [Backend] -> GitRepo -> FilePath -> FilePath -> IO Bool
-retrieveFile backends repo file dest = do
- result <- lookupBackend backends repo file
+retrieveFile :: [Backend] -> State -> FilePath -> FilePath -> IO Bool
+retrieveFile backends state file dest = do
+ result <- lookupBackend backends state file
case (result) of
Nothing -> return False
Just b -> do
- key <- lookupKey b repo file
+ key <- lookupKey b state file
(retrieveKeyFile b) key dest
{- Drops the key for a file from the backend that has it. -}
-dropFile :: [Backend] -> GitRepo -> FilePath -> IO (Maybe Key)
-dropFile backends repo file = do
- result <- lookupBackend backends repo file
+dropFile :: [Backend] -> State -> FilePath -> IO (Maybe Key)
+dropFile backends state file = do
+ result <- lookupBackend backends state file
case (result) of
Nothing -> return Nothing
Just b -> do
- key <- lookupKey b repo file
+ key <- lookupKey b state file
(removeKey b) key
- removeFile $ backendFile b repo file
+ removeFile $ backendFile b state file
return $ Just key
{- Looks up the key a backend uses for an already annexed file. -}
-lookupKey :: Backend -> GitRepo -> FilePath -> IO Key
-lookupKey backend repo file = readFile (backendFile backend repo file)
+lookupKey :: Backend -> State -> FilePath -> IO Key
+lookupKey backend state file = readFile (backendFile backend state file)
{- Looks up the backend used for an already annexed file. -}
-lookupBackend :: [Backend] -> GitRepo -> FilePath -> IO (Maybe Backend)
+lookupBackend :: [Backend] -> State -> FilePath -> IO (Maybe Backend)
lookupBackend [] _ _ = return Nothing
-lookupBackend (b:bs) repo file = do
- present <- checkBackend b repo file
+lookupBackend (b:bs) state file = do
+ present <- checkBackend b state file
if present
then
return $ Just b
else
- lookupBackend bs repo file
+ lookupBackend bs state file
{- Checks if a file is available via a given backend. -}
-checkBackend :: Backend -> GitRepo -> FilePath -> IO (Bool)
-checkBackend backend repo file = doesFileExist $ backendFile backend repo file
+checkBackend :: Backend -> State -> FilePath -> IO (Bool)
+checkBackend backend state file = doesFileExist $ backendFile backend state file