aboutsummaryrefslogtreecommitdiff
path: root/Annex.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-12 17:56:29 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-12 17:56:29 -0400
commit10992b90c97e8c6abfd26da3d6cb50011b4230b6 (patch)
tree413cac078d6ffe4dfc1d0bc521965b117398f5f0 /Annex.hs
parent3d2b44ffe58ddc2f235f71cb548ba4a43b6fe641 (diff)
avoid redownload
Diffstat (limited to 'Annex.hs')
-rw-r--r--Annex.hs26
1 files changed, 17 insertions, 9 deletions
diff --git a/Annex.hs b/Annex.hs
index 68379cf20..725009fd2 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -29,10 +29,14 @@ import Types
- used should be as close to the key as possible, in case the key is a
- filename or url. Just escape "/" in the key name, to keep a flat
- tree of files and avoid issues with files ending with "/" etc. -}
-annexLocation :: GitRepo -> Key -> FilePath
-annexLocation repo key = gitDir repo ++ "/annex/" ++ (transform key)
+annexLocation :: State -> Key -> FilePath
+annexLocation state key = gitDir (repo state) ++ "/annex/" ++ (transform key)
where transform s = replace "/" "%" $ replace "%" "%%" s
+{- Checks if a given key is currently present in the annexLocation -}
+inAnnex :: State -> Key -> IO Bool
+inAnnex state key = doesFileExist $ annexLocation state key
+
{- On startup, examine the git repo, prepare it, and record state for
- later. -}
startAnnex :: IO State
@@ -61,7 +65,7 @@ annexFile state file = do
Just key -> symlink key
where
symlink key = do
- let dest = annexLocation (repo state) key
+ let dest = annexLocation state key
createDirectoryIfMissing True (parentDir dest)
renameFile file dest
createSymbolicLink dest file
@@ -83,7 +87,7 @@ unannexFile state file = do
case (mkey) of
Nothing -> return ()
Just key -> do
- let src = annexLocation (repo state) key
+ let src = annexLocation state key
removeFile file
renameFile src file
return ()
@@ -96,12 +100,16 @@ annexGetFile state file = do
Nothing -> error $ "not annexed " ++ file
Just backend -> do
key <- lookupKey state backend file
- let dest = annexLocation (repo state) key
- createDirectoryIfMissing True (parentDir dest)
- success <- retrieveFile state file dest
- if (success)
+ inannex <- inAnnex state key
+ if (inannex)
then return ()
- else error $ "failed to get " ++ file
+ else do
+ let dest = annexLocation state key
+ createDirectoryIfMissing True (parentDir dest)
+ success <- retrieveFile state file dest
+ if (success)
+ then return ()
+ else error $ "failed to get " ++ file
{- Indicates a file is wanted. -}
annexWantFile :: State -> FilePath -> IO ()