cabal-dev 0.7.2 → 0.7.2.1
raw patch · 2 files changed
+33/−1 lines, 2 files
Files
- cabal-dev.cabal +2/−1
- src/Distribution/Dev/Utilities.hs +31/−0
cabal-dev.cabal view
@@ -1,5 +1,5 @@ Name: cabal-dev-Version: 0.7.2+Version: 0.7.2.1 Synopsis: Manage sandboxed Haskell build environments Description: cabal-dev is a tool for managing development builds of@@ -141,3 +141,4 @@ Distribution.Dev.InstallDependencies, Distribution.Dev.RewriteCabalConfig, Distribution.Dev.InitPkgDb+ Distribution.Dev.Utilities
+ src/Distribution/Dev/Utilities.hs view
@@ -0,0 +1,31 @@+module Distribution.Dev.Utilities+ ( makeAbsolute+ , makeAbsoluteToCurrentDirectory+ , ensureAbsolute+ ) where++import System.Directory ( getCurrentDirectory )+import System.FilePath ( (</>), isAbsolute, isRelative )++-- | Given a path, returns that path unmodified if it is absolute,+-- otherwise it is made absolute relative to the current directory.+ensureAbsolute :: FilePath -> IO FilePath+ensureAbsolute path | isAbsolute path = return path+ | otherwise = makeAbsoluteToCurrentDirectory path++-- | Makes a relative path into an absolute path, rooted in the+-- current directory. Throws an error if path is not relative.+makeAbsoluteToCurrentDirectory :: FilePath -> IO FilePath+makeAbsoluteToCurrentDirectory path = do cwd <- getCurrentDirectory+ case makeAbsolute cwd path of+ Left m -> error m+ Right p -> return p++-- | Creates an absolute file path from an absolute path and a+-- relative path. Does not normalize the result. makeAbsolute returns+-- Left msg if root is not absolute, or rel is not relative+makeAbsolute :: FilePath -> FilePath -> Either String FilePath+makeAbsolute root rel | not (isAbsolute root) = Left (root ++ " was not an absolute path.")+ | not (isRelative rel) = Left (rel ++ " was not a relative path.")+ | otherwise = Right (root </> rel)+