summaryrefslogtreecommitdiff
path: root/Backend.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-10 19:53:31 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-10 19:53:31 -0400
commit344f13394fe5b12cbdd5eeb99bb63892c7096bfd (patch)
tree478ad78d49e9c3515bee1cd2afd24d3e435a19eb /Backend.hs
parent93d2dc0d6878ccb1067376d2a03193c222429d3e (diff)
update
Diffstat (limited to 'Backend.hs')
-rw-r--r--Backend.hs23
1 files changed, 19 insertions, 4 deletions
diff --git a/Backend.hs b/Backend.hs
index 93ceee234..5ddd3aac6 100644
--- a/Backend.hs
+++ b/Backend.hs
@@ -57,14 +57,29 @@ storeFile (b:bs) repo file = do
{- Attempts to retrieve an file from one of the backends, saving it to
- a specified location. -}
-retrieveFile :: [Backend] -> GitRepo -> FilePath -> FilePath -> IO (Bool)
+retrieveFile :: [Backend] -> GitRepo -> FilePath -> FilePath -> IO Bool
retrieveFile backends repo file dest = do
result <- lookupBackend backends repo file
case (result) of
Nothing -> return False
- Just b -> (retrieveKeyFile b) key dest
- where
- key = readFile (backendFile b repo file)
+ Just b -> do
+ key <- lookupKey b repo 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
+ case (result) of
+ Nothing -> return Nothing
+ Just b -> do
+ key <- lookupKey b repo file
+ (removeKey b) key
+ 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)
{- Looks up the backend used for an already annexed file. -}
lookupBackend :: [Backend] -> GitRepo -> FilePath -> IO (Maybe Backend)