aboutsummaryrefslogtreecommitdiff
path: root/Backend.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-10 15:21:17 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-10 15:21:17 -0400
commit4631927a5c7b14605725f1c6f272fee19d8b4318 (patch)
tree822809146873eaa07fa96f5ff2c6e4b31f3fd87c /Backend.hs
parentcc235192353561a374c431485c6c3834659e0fa6 (diff)
fix storing files in .git/annex by key
Diffstat (limited to 'Backend.hs')
-rw-r--r--Backend.hs24
1 files changed, 16 insertions, 8 deletions
diff --git a/Backend.hs b/Backend.hs
index c55634a68..d6b433989 100644
--- a/Backend.hs
+++ b/Backend.hs
@@ -44,21 +44,29 @@ backendFile :: Backend -> GitRepo -> FilePath -> String
backendFile backend repo file = gitStateDir repo ++
(gitRelative repo file) ++ "." ++ (name backend)
-{- Attempts to Stores a file in one of the backends. -}
-storeFile :: [Backend] -> GitRepo -> FilePath -> IO (Bool)
-storeFile [] _ _ = return False
+{- Attempts to store a file in one of the backends, and returns
+ - its key. -}
+storeFile :: [Backend] -> GitRepo -> FilePath -> IO (Maybe Key)
+storeFile [] _ _ = return Nothing
storeFile (b:bs) repo file = do
try <- (getKey b) (gitRelative repo file)
case (try) of
- Nothing -> storeFile bs repo file
+ Nothing -> nextbackend
Just key -> do
- (storeFileKey b) file key
+ stored <- (storeFileKey b) 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
+ bookkeeping key = do
createDirectoryIfMissing True (parentDir backendfile)
writeFile backendfile key
- return True
- where backendfile = backendFile b repo file
-{- Attempts to retrieve an file from one of the backends, saving it to
+{- 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