summaryrefslogtreecommitdiff
path: root/Locations.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-01-27 17:00:32 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-01-27 17:00:32 -0400
commit167523f09d48777f3a5931fdcbc21b9d363e0e6c (patch)
tree698c1c601b39b617ccc02259053c3c39372ed5db /Locations.hs
parent6be516ae3bddb8f05ea62661019836e03be12a2c (diff)
better directory handling
Rename Locations functions for better consitency, and make their values more consistent too. Used </> rather than manually building paths. There are still more places that manually do so, but are tricky, due to the behavior of </> when the second FilePath is absolute. So I only changed places where it obviously was relative.
Diffstat (limited to 'Locations.hs')
-rw-r--r--Locations.hs74
1 files changed, 47 insertions, 27 deletions
diff --git a/Locations.hs b/Locations.hs
index 327c099e3..b2624754e 100644
--- a/Locations.hs
+++ b/Locations.hs
@@ -7,73 +7,93 @@
module Locations (
gitStateDir,
- stateLoc,
+ stateDir,
keyFile,
fileKey,
+ gitAnnexLocation,
annexLocation,
- annexLocationRelative,
- annexTmpLocation,
- annexBadLocation,
- annexUnusedLog,
+ gitAnnexDir,
+ gitAnnexObjectDir,
+ gitAnnexTmpDir,
+ gitAnnexBadDir,
+ gitAnnexUnusedLog,
isLinkToAnnex,
- annexDir,
- annexObjectDir,
prop_idempotent_fileKey
) where
+import System.FilePath
import Data.String.Utils
import Data.List
import Types
import qualified GitRepo as Git
+{- Conventions:
+ -
+ - Functions ending in "Dir" should always return values ending with a
+ - trailing path separator. Most code does not rely on that, but a few
+ - things do.
+ -
+ - Everything else should not end in a trailing path sepatator.
+ -
+ - Only functions (with names starting with "git") that build a path
+ - based on a git repository should return an absolute path.
+ - Everything else should use relative paths.
+ -}
+
{- Long-term, cross-repo state is stored in files inside the .git-annex
- directory, in the git repository's working tree. -}
-stateLoc :: String
-stateLoc = ".git-annex/"
+stateDir :: FilePath
+stateDir = addTrailingPathSeparator $ ".git-annex"
gitStateDir :: Git.Repo -> FilePath
-gitStateDir repo = Git.workTree repo ++ "/" ++ stateLoc
+gitStateDir repo = addTrailingPathSeparator $ Git.workTree repo </> stateDir
-{- Annexed file's absolute location. -}
-annexLocation :: Git.Repo -> Key -> FilePath
-annexLocation r key =
- Git.workTree r ++ "/" ++ annexLocationRelative key
+{- Annexed content is stored in .git/annex/objects; .git/annex is used
+ - for other temporary storage also. -}
+annexDir :: FilePath
+annexDir = addTrailingPathSeparator $ ".git/annex"
+objectDir :: FilePath
+objectDir = addTrailingPathSeparator $ annexDir </> "objects"
{- Annexed file's location relative to git's working tree.
-
- Note: Assumes repo is NOT bare.-}
-annexLocationRelative :: Key -> FilePath
-annexLocationRelative key = ".git/annex/objects/" ++ f ++ "/" ++ f
+annexLocation :: Key -> FilePath
+annexLocation key = ".git/annex/objects" </> f </> f
where
f = keyFile key
+{- Annexed file's absolute location in a repository. -}
+gitAnnexLocation :: Git.Repo -> Key -> FilePath
+gitAnnexLocation r key = Git.workTree r </> annexLocation key
+
{- The annex directory of a repository.
-
- Note: Assumes repo is NOT bare. -}
-annexDir :: Git.Repo -> FilePath
-annexDir r = Git.workTree r ++ "/.git/annex"
+gitAnnexDir :: Git.Repo -> FilePath
+gitAnnexDir r = addTrailingPathSeparator $ Git.workTree r </> annexDir
{- The part of the annex directory where file contents are stored.
-}
-annexObjectDir :: Git.Repo -> FilePath
-annexObjectDir r = annexDir r ++ "/objects"
+gitAnnexObjectDir :: Git.Repo -> FilePath
+gitAnnexObjectDir r = addTrailingPathSeparator $ Git.workTree r </> objectDir
{- .git-annex/tmp/ is used for temp files -}
-annexTmpLocation :: Git.Repo -> FilePath
-annexTmpLocation r = annexDir r ++ "/tmp/"
+gitAnnexTmpDir :: Git.Repo -> FilePath
+gitAnnexTmpDir r = addTrailingPathSeparator $ gitAnnexDir r </> "tmp"
{- .git-annex/bad/ is used for bad files found during fsck -}
-annexBadLocation :: Git.Repo -> FilePath
-annexBadLocation r = annexDir r ++ "/bad/"
+gitAnnexBadDir :: Git.Repo -> FilePath
+gitAnnexBadDir r = addTrailingPathSeparator $ gitAnnexDir r </> "bad"
{- .git/annex/unused is used to number possibly unused keys -}
-annexUnusedLog :: Git.Repo -> FilePath
-annexUnusedLog r = annexDir r ++ "/unused"
+gitAnnexUnusedLog :: Git.Repo -> FilePath
+gitAnnexUnusedLog r = gitAnnexDir r </> "unused"
{- Checks a symlink target to see if it appears to point to annexed content. -}
isLinkToAnnex :: FilePath -> Bool
-isLinkToAnnex s = isInfixOf "/.git/annex/objects/" s
+isLinkToAnnex s = isInfixOf ("/" ++ objectDir) s
{- Converts a key into a filename fragment.
-