avoid redownload
This commit is contained in:
parent
3d2b44ffe5
commit
10992b90c9
2 changed files with 17 additions and 11 deletions
26
Annex.hs
26
Annex.hs
|
@ -29,10 +29,14 @@ import Types
|
||||||
- used should be as close to the key as possible, in case the key is a
|
- 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
|
- filename or url. Just escape "/" in the key name, to keep a flat
|
||||||
- tree of files and avoid issues with files ending with "/" etc. -}
|
- tree of files and avoid issues with files ending with "/" etc. -}
|
||||||
annexLocation :: GitRepo -> Key -> FilePath
|
annexLocation :: State -> Key -> FilePath
|
||||||
annexLocation repo key = gitDir repo ++ "/annex/" ++ (transform key)
|
annexLocation state key = gitDir (repo state) ++ "/annex/" ++ (transform key)
|
||||||
where transform s = replace "/" "%" $ replace "%" "%%" s
|
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
|
{- On startup, examine the git repo, prepare it, and record state for
|
||||||
- later. -}
|
- later. -}
|
||||||
startAnnex :: IO State
|
startAnnex :: IO State
|
||||||
|
@ -61,7 +65,7 @@ annexFile state file = do
|
||||||
Just key -> symlink key
|
Just key -> symlink key
|
||||||
where
|
where
|
||||||
symlink key = do
|
symlink key = do
|
||||||
let dest = annexLocation (repo state) key
|
let dest = annexLocation state key
|
||||||
createDirectoryIfMissing True (parentDir dest)
|
createDirectoryIfMissing True (parentDir dest)
|
||||||
renameFile file dest
|
renameFile file dest
|
||||||
createSymbolicLink dest file
|
createSymbolicLink dest file
|
||||||
|
@ -83,7 +87,7 @@ unannexFile state file = do
|
||||||
case (mkey) of
|
case (mkey) of
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
Just key -> do
|
Just key -> do
|
||||||
let src = annexLocation (repo state) key
|
let src = annexLocation state key
|
||||||
removeFile file
|
removeFile file
|
||||||
renameFile src file
|
renameFile src file
|
||||||
return ()
|
return ()
|
||||||
|
@ -96,12 +100,16 @@ annexGetFile state file = do
|
||||||
Nothing -> error $ "not annexed " ++ file
|
Nothing -> error $ "not annexed " ++ file
|
||||||
Just backend -> do
|
Just backend -> do
|
||||||
key <- lookupKey state backend file
|
key <- lookupKey state backend file
|
||||||
let dest = annexLocation (repo state) key
|
inannex <- inAnnex state key
|
||||||
createDirectoryIfMissing True (parentDir dest)
|
if (inannex)
|
||||||
success <- retrieveFile state file dest
|
|
||||||
if (success)
|
|
||||||
then return ()
|
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. -}
|
{- Indicates a file is wanted. -}
|
||||||
annexWantFile :: State -> FilePath -> IO ()
|
annexWantFile :: State -> FilePath -> IO ()
|
||||||
|
|
2
TODO
2
TODO
|
@ -1,7 +1,5 @@
|
||||||
* bug when annexing files in a subdir of a git repo
|
* bug when annexing files in a subdir of a git repo
|
||||||
* how to handle git mv file?
|
* how to handle git mv file?
|
||||||
* if curl fails to download, git-annex crashes and does not complete
|
|
||||||
further actions.. exception seems to somehow not get caught
|
|
||||||
|
|
||||||
* query remotes for their annex.uuid settings
|
* query remotes for their annex.uuid settings
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue