2010-10-10 19:54:02 +00:00
|
|
|
{- git-annex file locations
|
|
|
|
-}
|
|
|
|
|
2010-10-11 21:52:46 +00:00
|
|
|
module Locations (
|
|
|
|
gitStateDir,
|
2010-10-13 00:04:36 +00:00
|
|
|
stateLoc,
|
|
|
|
keyFile,
|
2010-10-13 07:41:12 +00:00
|
|
|
fileKey,
|
2010-10-13 04:58:59 +00:00
|
|
|
annexLocation,
|
|
|
|
annexLocationRelative
|
2010-10-11 21:52:46 +00:00
|
|
|
) where
|
2010-10-10 19:54:02 +00:00
|
|
|
|
2010-10-13 00:04:36 +00:00
|
|
|
import Data.String.Utils
|
|
|
|
import Types
|
2010-10-10 19:54:02 +00:00
|
|
|
import GitRepo
|
|
|
|
|
2010-10-11 04:23:49 +00:00
|
|
|
{- Long-term, cross-repo state is stored in files inside the .git-annex
|
2010-10-12 04:53:42 +00:00
|
|
|
- directory, in the git repository's working tree. -}
|
2010-10-10 19:54:02 +00:00
|
|
|
stateLoc = ".git-annex"
|
|
|
|
gitStateDir :: GitRepo -> FilePath
|
2010-10-12 04:53:42 +00:00
|
|
|
gitStateDir repo = (gitWorkTree repo) ++ "/" ++ stateLoc ++ "/"
|
2010-10-13 00:04:36 +00:00
|
|
|
|
2010-10-13 04:42:46 +00:00
|
|
|
{- 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
|
2010-10-13 04:58:59 +00:00
|
|
|
annexLocation state backend key =
|
|
|
|
(gitWorkTree $ repo state) ++ "/" ++
|
|
|
|
(annexLocationRelative state backend key)
|
2010-10-13 05:04:06 +00:00
|
|
|
|
2010-10-13 05:36:20 +00:00
|
|
|
{- Annexed file's location relative to the gitWorkTree -}
|
2010-10-13 04:58:59 +00:00
|
|
|
annexLocationRelative :: State -> Backend -> Key -> FilePath
|
2010-10-13 05:36:20 +00:00
|
|
|
annexLocationRelative state backend key =
|
2010-10-13 04:42:46 +00:00
|
|
|
gitDir (repo state) ++ "/annex/" ++ (name backend) ++
|
|
|
|
"/" ++ (keyFile key)
|
2010-10-13 07:41:12 +00:00
|
|
|
|
|
|
|
{- Converts a key into a filename fragment.
|
|
|
|
-
|
|
|
|
- Escape "/" in the key name, to keep a flat tree of files and avoid
|
|
|
|
- issues with keys containing "/../" or ending with "/" etc.
|
|
|
|
-
|
|
|
|
- "/" is escaped to "%" because it's short and rarely used, and resembles
|
|
|
|
- a slash
|
|
|
|
- "%" is escaped to "&s", and "&" to "&a"; this ensures that the mapping
|
|
|
|
- is one to one.
|
|
|
|
- -}
|
|
|
|
keyFile :: Key -> FilePath
|
|
|
|
keyFile key = replace "/" "%" $ replace "%" "&s" $ replace "&" "&a" $ show key
|
|
|
|
|
|
|
|
{- Reverses keyFile -}
|
|
|
|
fileKey :: FilePath -> Key
|
|
|
|
fileKey file = Key $ replace "&a" "&" $ replace "&s" "%" $ replace "%" "/" file
|