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,
|
2010-10-17 20:39:30 +00:00
|
|
|
annexLocationRelative,
|
|
|
|
annexTmpLocation
|
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
|
2010-10-16 20:20:49 +00:00
|
|
|
|
2010-10-14 07:18:11 +00:00
|
|
|
import Types
|
2010-10-18 06:06:27 +00:00
|
|
|
import qualified TypeInternals as Internals
|
2010-10-14 06:36:41 +00:00
|
|
|
import qualified GitRepo as Git
|
2010-10-10 19:54:02 +00:00
|
|
|
|
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-17 02:36:35 +00:00
|
|
|
stateLoc = ".git-annex/"
|
2010-10-14 06:36:41 +00:00
|
|
|
gitStateDir :: Git.Repo -> FilePath
|
2010-10-17 02:36:35 +00:00
|
|
|
gitStateDir repo = (Git.workTree 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
|
2010-10-14 23:36:11 +00:00
|
|
|
- /path/to/repo/.git/annex/<key>, where <key> is of the form
|
|
|
|
- <backend:fragment>
|
2010-10-13 20:21:50 +00:00
|
|
|
-
|
2010-10-14 23:36:11 +00:00
|
|
|
- That allows deriving the key and backend by looking at the symlink to it.
|
2010-10-13 20:21:50 +00:00
|
|
|
-}
|
2010-10-14 23:36:11 +00:00
|
|
|
annexLocation :: Git.Repo -> Key -> FilePath
|
|
|
|
annexLocation r key =
|
|
|
|
(Git.workTree r) ++ "/" ++ (annexLocationRelative r key)
|
2010-10-13 05:04:06 +00:00
|
|
|
|
2010-10-15 20:09:30 +00:00
|
|
|
{- Annexed file's location relative to git's working tree. -}
|
2010-10-14 23:36:11 +00:00
|
|
|
annexLocationRelative :: Git.Repo -> Key -> FilePath
|
2010-10-15 20:09:30 +00:00
|
|
|
annexLocationRelative r key = Git.dir r ++ "/annex/" ++ (keyFile key)
|
2010-10-13 07:41:12 +00:00
|
|
|
|
2010-10-17 20:39:30 +00:00
|
|
|
{- .git-annex/tmp is used for temp files
|
|
|
|
-}
|
|
|
|
annexTmpLocation :: Git.Repo -> FilePath
|
|
|
|
annexTmpLocation r = (Git.workTree r) ++ "/" ++ Git.dir r ++ "/annex/tmp/"
|
|
|
|
|
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
|
|
|
|
|
2010-10-14 03:31:08 +00:00
|
|
|
{- Reverses keyFile, converting a filename fragment (ie, the basename of
|
|
|
|
- the symlink target) into a key. -}
|
2010-10-13 07:41:12 +00:00
|
|
|
fileKey :: FilePath -> Key
|
2010-10-14 23:36:11 +00:00
|
|
|
fileKey file = read $
|
2010-10-14 06:52:17 +00:00
|
|
|
replace "&a" "&" $ replace "&s" "%" $ replace "%" "/" file
|