summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Annex.hs11
-rw-r--r--Backend.hs44
-rw-r--r--CmdLine.hs1
3 files changed, 28 insertions, 28 deletions
diff --git a/Annex.hs b/Annex.hs
index 78d990eac..1752cabff 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -2,7 +2,6 @@
-}
module Annex (
- State,
startAnnex,
annexFile,
unannexFile,
@@ -45,12 +44,12 @@ startAnnex = do
- the annex directory and setting up the symlink pointing to its content. -}
annexFile :: State -> FilePath -> IO ()
annexFile state file = do
- alreadyannexed <- lookupBackend (backends state) state file
+ alreadyannexed <- lookupBackend state file
case (alreadyannexed) of
Just _ -> error $ "already annexed: " ++ file
Nothing -> do
checkLegal file
- stored <- storeFile (backends state) state file
+ stored <- storeFile state file
case (stored) of
Nothing -> error $ "no backend could store: " ++ file
Just key -> symlink key
@@ -70,11 +69,11 @@ annexFile state file = do
{- Inverse of annexFile. -}
unannexFile :: State -> FilePath -> IO ()
unannexFile state file = do
- alreadyannexed <- lookupBackend (backends state) state file
+ alreadyannexed <- lookupBackend state file
case (alreadyannexed) of
Nothing -> error $ "not annexed " ++ file
Just _ -> do
- mkey <- dropFile (backends state) state file
+ mkey <- dropFile state file
case (mkey) of
Nothing -> return ()
Just key -> do
@@ -86,7 +85,7 @@ unannexFile state file = do
{- Transfers the file from a remote. -}
annexGetFile :: State -> FilePath -> IO ()
annexGetFile state file = do
- alreadyannexed <- lookupBackend (backends state) state file
+ alreadyannexed <- lookupBackend state file
case (alreadyannexed) of
Nothing -> error $ "not annexed " ++ file
Just _ -> do error "not implemented" -- TODO
diff --git a/Backend.hs b/Backend.hs
index 622d558e3..2e5275ba6 100644
--- a/Backend.hs
+++ b/Backend.hs
@@ -17,8 +17,6 @@
- -}
module Backend (
- Key,
- Backend, -- note only data type is exported, not destructors
lookupBackend,
storeFile,
dropFile
@@ -32,16 +30,17 @@ import Types
{- Name of state file that holds the key for an annexed file,
- using a given backend. -}
-backendFile :: Backend -> State -> FilePath -> String
-backendFile backend state file =
+backendFile :: State -> Backend -> FilePath -> String
+backendFile state backend 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] -> State -> FilePath -> IO (Maybe Key)
-storeFile [] _ _ = return Nothing
-storeFile (b:bs) state file = do
+storeFile :: State -> FilePath -> IO (Maybe Key)
+storeFile state file = storeFile' (backends state) state file
+storeFile' [] _ _ = return Nothing
+storeFile' (b:bs) state file = do
try <- (getKey b) state (gitRelative (repo state) file)
case (try) of
Nothing -> nextbackend
@@ -53,17 +52,17 @@ storeFile (b:bs) state file = do
bookkeeping key
return $ Just key
where
- nextbackend = storeFile bs state file
- backendfile = backendFile b state file
+ nextbackend = storeFile' bs state file
+ backendfile = backendFile state b 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] -> State -> FilePath -> FilePath -> IO Bool
-retrieveFile backends state file dest = do
- result <- lookupBackend backends state file
+retrieveFile :: State -> FilePath -> FilePath -> IO Bool
+retrieveFile state file dest = do
+ result <- lookupBackend state file
case (result) of
Nothing -> return False
Just b -> do
@@ -71,32 +70,33 @@ retrieveFile backends state file dest = do
(retrieveKeyFile b) state key dest
{- Drops the key for a file from the backend that has it. -}
-dropFile :: [Backend] -> State -> FilePath -> IO (Maybe Key)
-dropFile backends state file = do
- result <- lookupBackend backends state file
+dropFile :: State -> FilePath -> IO (Maybe Key)
+dropFile state file = do
+ result <- lookupBackend state file
case (result) of
Nothing -> return Nothing
Just b -> do
key <- lookupKey b state file
(removeKey b) state key
- removeFile $ backendFile b state file
+ removeFile $ backendFile state b file
return $ Just key
{- Looks up the key a backend uses for an already annexed file. -}
lookupKey :: Backend -> State -> FilePath -> IO Key
-lookupKey backend state file = readFile (backendFile backend state file)
+lookupKey backend state file = readFile (backendFile state backend file)
{- Looks up the backend used for an already annexed file. -}
-lookupBackend :: [Backend] -> State -> FilePath -> IO (Maybe Backend)
-lookupBackend [] _ _ = return Nothing
-lookupBackend (b:bs) state file = do
+lookupBackend :: State -> FilePath -> IO (Maybe Backend)
+lookupBackend state file = lookupBackend' (backends state) state file
+lookupBackend' [] _ _ = return Nothing
+lookupBackend' (b:bs) state file = do
present <- checkBackend b state file
if present
then
return $ Just b
else
- lookupBackend bs state file
+ lookupBackend' bs state file
{- Checks if a file is available via a given backend. -}
checkBackend :: Backend -> State -> FilePath -> IO (Bool)
-checkBackend backend state file = doesFileExist $ backendFile backend state file
+checkBackend backend state file = doesFileExist $ backendFile state backend file
diff --git a/CmdLine.hs b/CmdLine.hs
index 60ba81d30..9da2b6493 100644
--- a/CmdLine.hs
+++ b/CmdLine.hs
@@ -10,6 +10,7 @@ module CmdLine (
) where
import System.Console.GetOpt
+import Types
import Annex
data Mode = Add | Push | Pull | Want | Get | Drop | Unannex