summaryrefslogtreecommitdiff
path: root/Locations.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-13 03:41:12 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-13 03:41:12 -0400
commit99b2029236248f6b4ce68e126b70fa0855fac37f (patch)
tree74e373992ecfac6543245f4ab9f86bf54fdf8d11 /Locations.hs
parentcc5cf0093ea1aacc4c5460dfdd4d35f2963687bd (diff)
key conversion back from file bugfixes
Diffstat (limited to 'Locations.hs')
-rw-r--r--Locations.hs31
1 files changed, 18 insertions, 13 deletions
diff --git a/Locations.hs b/Locations.hs
index a99ad6ec4..304ca060e 100644
--- a/Locations.hs
+++ b/Locations.hs
@@ -5,6 +5,7 @@ module Locations (
gitStateDir,
stateLoc,
keyFile,
+ fileKey,
annexLocation,
annexLocationRelative
) where
@@ -19,19 +20,6 @@ stateLoc = ".git-annex"
gitStateDir :: GitRepo -> FilePath
gitStateDir repo = (gitWorkTree repo) ++ "/" ++ stateLoc ++ "/"
-{- 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
-
{- 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. -}
@@ -45,3 +33,20 @@ annexLocationRelative :: State -> Backend -> Key -> FilePath
annexLocationRelative state backend key =
gitDir (repo state) ++ "/annex/" ++ (name backend) ++
"/" ++ (keyFile key)
+
+{- 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