better key to file mapping
This commit is contained in:
parent
67ae9d7fa1
commit
16cd682290
1 changed files with 11 additions and 3 deletions
14
Locations.hs
14
Locations.hs
|
@ -20,10 +20,17 @@ gitStateDir :: GitRepo -> FilePath
|
||||||
gitStateDir repo = (gitWorkTree repo) ++ "/" ++ stateLoc ++ "/"
|
gitStateDir repo = (gitWorkTree repo) ++ "/" ++ stateLoc ++ "/"
|
||||||
|
|
||||||
{- Converts a key into a filename fragment.
|
{- Converts a key into a filename fragment.
|
||||||
- Just escape "/" in the key name, to keep a flat
|
-
|
||||||
- tree of files and avoid issues with files ending with "/" etc. -}
|
- 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 -> FilePath
|
||||||
keyFile key = replace "/" "&s" $ replace "&" "&a" key
|
keyFile key = replace "/" "%" $ replace "%" "%s" $ replace "&" "&a" key
|
||||||
|
|
||||||
{- An annexed file's content is stored in
|
{- An annexed file's content is stored in
|
||||||
- .git/annex/<backend>/<key> ; this allows deriving the key and backend
|
- .git/annex/<backend>/<key> ; this allows deriving the key and backend
|
||||||
|
@ -32,6 +39,7 @@ annexLocation :: State -> Backend -> Key -> FilePath
|
||||||
annexLocation state backend key =
|
annexLocation state backend key =
|
||||||
(gitWorkTree $ repo state) ++ "/" ++
|
(gitWorkTree $ repo state) ++ "/" ++
|
||||||
(annexLocationRelative state backend key)
|
(annexLocationRelative state backend key)
|
||||||
|
|
||||||
annexLocationRelative :: State -> Backend -> Key -> FilePath
|
annexLocationRelative :: State -> Backend -> Key -> FilePath
|
||||||
annexLocationRelative state backend key =
|
annexLocationRelative state backend key =
|
||||||
gitDir (repo state) ++ "/annex/" ++ (name backend) ++
|
gitDir (repo state) ++ "/annex/" ++ (name backend) ++
|
||||||
|
|
Loading…
Reference in a new issue