got rid of the .git-annex/key.backend files
This commit is contained in:
parent
9926fe5c8a
commit
208bba8d30
5 changed files with 52 additions and 65 deletions
24
Annex.hs
24
Annex.hs
|
@ -25,8 +25,8 @@ import LocationLog
|
|||
import Types
|
||||
|
||||
{- Checks if a given key is currently present in the annexLocation -}
|
||||
inAnnex :: State -> Key -> IO Bool
|
||||
inAnnex state key = doesFileExist $ annexLocation state key
|
||||
inAnnex :: State -> Backend -> Key -> IO Bool
|
||||
inAnnex state backend key = doesFileExist $ annexLocation state backend key
|
||||
|
||||
{- On startup, examine the git repo, prepare it, and record state for
|
||||
- later. -}
|
||||
|
@ -56,15 +56,14 @@ annexFile state file = do
|
|||
Just (key, backend) -> setup key backend
|
||||
where
|
||||
setup key backend = do
|
||||
let dest = annexLocation state key
|
||||
let dest = annexLocation state backend key
|
||||
createDirectoryIfMissing True (parentDir dest)
|
||||
renameFile file dest
|
||||
createSymbolicLink dest file
|
||||
gitRun (repo state) ["add", file, bfile]
|
||||
gitRun (repo state) ["add", file]
|
||||
gitRun (repo state) ["commit", "-m",
|
||||
("git-annex annexed " ++ file), file, bfile]
|
||||
("git-annex annexed " ++ file), file]
|
||||
logStatus state key ValuePresent
|
||||
where bfile = backendFile state backend file
|
||||
checkLegal file = do
|
||||
s <- getSymbolicLinkStatus file
|
||||
if ((isSymbolicLink s) || (not $ isRegularFile s))
|
||||
|
@ -82,16 +81,15 @@ unannexFile state file = do
|
|||
case (mkey) of
|
||||
Nothing -> return ()
|
||||
Just (key, backend) -> do
|
||||
let src = annexLocation state key
|
||||
let src = annexLocation state backend key
|
||||
removeFile file
|
||||
gitRun (repo state) ["rm", file, bfile]
|
||||
gitRun (repo state) ["rm", file]
|
||||
gitRun (repo state) ["commit", "-m",
|
||||
("git-annex unannexed " ++ file),
|
||||
file, bfile]
|
||||
file]
|
||||
renameFile src file
|
||||
logStatus state key ValueMissing
|
||||
return ()
|
||||
where bfile = backendFile state backend file
|
||||
|
||||
{- Transfers the file from a remote. -}
|
||||
annexGetFile :: State -> FilePath -> IO ()
|
||||
|
@ -100,12 +98,12 @@ annexGetFile state file = do
|
|||
case (alreadyannexed) of
|
||||
Nothing -> error $ "not annexed " ++ file
|
||||
Just backend -> do
|
||||
key <- lookupKey state backend file
|
||||
inannex <- inAnnex state key
|
||||
key <- fileKey file
|
||||
inannex <- inAnnex state backend key
|
||||
if (inannex)
|
||||
then return ()
|
||||
else do
|
||||
let dest = annexLocation state key
|
||||
let dest = annexLocation state backend key
|
||||
createDirectoryIfMissing True (parentDir dest)
|
||||
success <- retrieveFile state file dest
|
||||
if (success)
|
||||
|
|
46
Backend.hs
46
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
|
||||
|
|
22
Locations.hs
22
Locations.hs
|
@ -5,8 +5,7 @@ module Locations (
|
|||
gitStateDir,
|
||||
stateLoc,
|
||||
keyFile,
|
||||
annexLocation,
|
||||
backendFile
|
||||
annexLocation
|
||||
) where
|
||||
|
||||
import Data.String.Utils
|
||||
|
@ -25,15 +24,10 @@ gitStateDir repo = (gitWorkTree repo) ++ "/" ++ stateLoc ++ "/"
|
|||
keyFile :: Key -> FilePath
|
||||
keyFile key = replace "/" "&s" $ replace "&" "&a" key
|
||||
|
||||
{- An annexed file's content is stored somewhere under .git/annex/,
|
||||
- based on the key. -}
|
||||
annexLocation :: State -> Key -> FilePath
|
||||
annexLocation state key = gitDir (repo state) ++ "/annex/" ++ (keyFile key)
|
||||
|
||||
{- The mapping from filename to its key is stored in the .git-annex directory,
|
||||
- in a file named `key/$filename.$backend` -}
|
||||
backendFile :: State -> Backend -> FilePath -> String
|
||||
backendFile state backend file =
|
||||
gitStateDir (repo state) ++ "key/" ++
|
||||
(gitRelative (repo state) file) ++
|
||||
"." ++ (name backend)
|
||||
{- An annexed file's content is stored in
|
||||
- .git/annex/<backend>/<key> ; this allows deriving the key and backend
|
||||
- by looking at the symlink to it. -}
|
||||
annexLocation :: State -> Backend -> Key -> FilePath
|
||||
annexLocation state backend key =
|
||||
gitDir (repo state) ++ "/annex/" ++ (name backend) ++
|
||||
"/" ++ (keyFile key)
|
||||
|
|
7
TODO
7
TODO
|
@ -1,6 +1,13 @@
|
|||
* bug when annexing files in a subdir of a git repo
|
||||
* how to handle git mv file?
|
||||
|
||||
* if the annexed files were in .git/annex/<backend>/key, and
|
||||
files in the repo symlink to that, the .git-annex/key/<file>.<backend>
|
||||
would be redundant, and not needed
|
||||
|
||||
-- no separate merge problem with it
|
||||
-- want to add an url? `ln -s .git/annex/<backend>/http:%%kitenet.net%foo myfile`
|
||||
|
||||
* implement retrieval for backendfile
|
||||
|
||||
* query remotes for their annex.uuid settings
|
||||
|
|
|
@ -91,11 +91,9 @@ used to store the file contents, and git-annex would then retrieve them
|
|||
as needed and put them in `.git/annex/`.
|
||||
|
||||
When a file is annexed, a key is generated from its content and/or metadata.
|
||||
This key can later be used to retrieve the file's content (its value). This
|
||||
key generation must be stable for a given file content, name, and size.
|
||||
|
||||
The mapping from filename to its key is stored in the .git-annex directory,
|
||||
in a file named `key/$filename.$backend`
|
||||
The file checked into git symlinks to the key. This key can later be used
|
||||
to retrieve the file's content (its value). This key generation must be
|
||||
stable for a given file content, name, and size.
|
||||
|
||||
Multiple pluggable backends are supported, and more than one can be used
|
||||
to store different files' contents in a given repository.
|
||||
|
@ -183,8 +181,8 @@ not be dropped right away, depending on number of copies available.
|
|||
|
||||
### branching
|
||||
|
||||
The use of `.git-annex` to store state means that if a repo has branches
|
||||
and the user switched between them, git-annex will see different state in
|
||||
the different branches. Whether that is a bug or a feature may depend on
|
||||
point of view -- call it Too Be Determined. An alternative would be to
|
||||
store data directly in the git repo as `pristine-tar` does.
|
||||
The use of `.git-annex` to store logs means that if a repo has branches
|
||||
and the user switched between them, git-annex will see different logs in
|
||||
the different branches, and so may miss info about what remotes have which
|
||||
files (though it can re-learn). An alternative would be to
|
||||
store the log data directly in the git repo as `pristine-tar` does.
|
||||
|
|
Loading…
Reference in a new issue