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.
This commit is contained in:
parent
6be516ae3b
commit
167523f09d
16 changed files with 78 additions and 57 deletions
74
Locations.hs
74
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.
|
||||
-
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue