aboutsummaryrefslogtreecommitdiff
path: root/Backend.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-13 00:42:46 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-13 00:42:46 -0400
commit208bba8d3062133733d27a5db521013e3a2ead57 (patch)
tree0a54c5cc7899329a13f995b57f32d25dceb17016 /Backend.hs
parent9926fe5c8a1479f734c0a5b68c7c4e6ddfc2f8cf (diff)
got rid of the .git-annex/key.backend files
Diffstat (limited to 'Backend.hs')
-rw-r--r--Backend.hs46
1 files changed, 18 insertions, 28 deletions
diff --git a/Backend.hs b/Backend.hs
index 525a52bee..68d70feec 100644
--- a/Backend.hs
+++ b/Backend.hs
@@ -17,12 +17,14 @@ module Backend (
lookupBackend,
storeFile,
retrieveFile,
- lookupKey,
+ fileKey,
dropFile
) where
import System.Directory
+import System.FilePath
import Data.String.Utils
+import System.Posix.Files
import Locations
import GitRepo
import Utility
@@ -41,7 +43,6 @@ storeFile' (b:bs) state file = do
if (not stored)
then nextbackend
else do
- recordKey state b file key
return $ Just (key, b)
where
nextbackend = storeFile' bs state file
@@ -53,9 +54,9 @@ retrieveFile state file dest = do
result <- lookupBackend state file
case (result) of
Nothing -> return False
- Just b -> do
- key <- lookupKey state b file
- (retrieveKeyFile b) state key dest
+ Just backend -> do
+ key <- fileKey file
+ (retrieveKeyFile backend) state key dest
{- Drops the key for a file from the backend that has it. -}
dropFile :: State -> FilePath -> IO (Maybe (Key, Backend))
@@ -63,11 +64,10 @@ dropFile state file = do
result <- lookupBackend state file
case (result) of
Nothing -> return Nothing
- Just b -> do
- key <- lookupKey state b file
- (removeKey b) state key
- removeFile $ backendFile state b file
- return $ Just (key, b)
+ Just backend -> do
+ key <- fileKey file
+ (removeKey backend) state key
+ return $ Just (key, backend)
{- Looks up the backend used for an already annexed file. -}
lookupBackend :: State -> FilePath -> IO (Maybe Backend)
@@ -83,22 +83,12 @@ lookupBackend' (b:bs) state file = do
{- Checks if a file is available via a given backend. -}
checkBackend :: Backend -> State -> FilePath -> IO (Bool)
-checkBackend backend state file = doesFileExist $ backendFile state backend file
+checkBackend backend state file =
+ doesFileExist $ annexLocation state backend file
-{- Looks up the key a backend uses for an already annexed file. -}
-lookupKey :: State -> Backend -> FilePath -> IO Key
-lookupKey state backend file = do
- k <- readFile (backendFile state backend file)
- return $ chomp k
- where
- chomp s = if (endswith "\n" s)
- then (reverse . (drop 1) . reverse) s
- else s
-
-{- Records the key used for an annexed file. -}
-recordKey :: State -> Backend -> FilePath -> Key -> IO ()
-recordKey state backend file key = do
- createDirectoryIfMissing True (parentDir record)
- writeFile record $ key ++ "\n"
- where
- record = backendFile state backend file
+{- Looks up the key corresponding to an annexed file,
+ - by examining what the file symlinks to. -}
+fileKey :: FilePath -> IO Key
+fileKey file = do
+ l <- readSymbolicLink (file)
+ return $ takeFileName $ l