summaryrefslogtreecommitdiff
path: root/Locations.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-08 16:47:36 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-08 17:00:34 -0400
commit6395b790ce3d2f97803f0c642af71d1a9eb169c6 (patch)
tree76ac64f2451d138e8cf476b5d66d2e4594686cdf /Locations.hs
parentba59ac13b25d5be671e38cb7b4c40257f3fdac4f (diff)
Reorganised the layout of .git/annex/
Diffstat (limited to 'Locations.hs')
-rw-r--r--Locations.hs23
1 files changed, 13 insertions, 10 deletions
diff --git a/Locations.hs b/Locations.hs
index 78c0bff4b..e5f78a31c 100644
--- a/Locations.hs
+++ b/Locations.hs
@@ -14,7 +14,9 @@ module Locations (
annexLocationRelative,
annexTmpLocation,
annexDir,
- annexObjectDir
+ annexObjectDir,
+
+ prop_idempotent_fileKey
) where
import Data.String.Utils
@@ -29,12 +31,7 @@ stateLoc = ".git-annex/"
gitStateDir :: Git.Repo -> FilePath
gitStateDir repo = (Git.workTree repo) ++ "/" ++ stateLoc
-{- An annexed file's content is stored in
- - /path/to/repo/.git/annex/objects/<key>/<key>, where <key> is of the form
- - <backend:fragment>
- -
- - That allows deriving the key and backend by looking at the symlink to it.
- -}
+{- Annexed file's absolute location. -}
annexLocation :: Git.Repo -> Key -> FilePath
annexLocation r key =
(Git.workTree r) ++ "/" ++ (annexLocationRelative key)
@@ -43,8 +40,9 @@ annexLocation r key =
-
- Note: Assumes repo is NOT bare.-}
annexLocationRelative :: Key -> FilePath
-annexLocationRelative key = ".git/annex/objects/" ++ f ++ f
- where f = keyFile key
+annexLocationRelative key = ".git/annex/objects/" ++ f ++ "/" ++ f
+ where
+ f = keyFile key
{- The annex directory of a repository.
-
@@ -72,10 +70,15 @@ annexTmpLocation r = annexDir r ++ "/tmp/"
- is one to one.
- -}
keyFile :: Key -> FilePath
-keyFile key = replace "/" "%" $ replace "%" "&s" $ replace "&" "&a" $ show key
+keyFile key = replace "/" "%" $ replace "%" "&s" $ replace "&" "&a" $ show key
{- Reverses keyFile, converting a filename fragment (ie, the basename of
- the symlink target) into a key. -}
fileKey :: FilePath -> Key
fileKey file = read $
replace "&a" "&" $ replace "&s" "%" $ replace "%" "/" file
+
+{- for quickcheck -}
+prop_idempotent_fileKey :: String -> Bool
+prop_idempotent_fileKey s = k == (fileKey $ keyFile k)
+ where k = read "test:s"