From d400c8f38958e413e83773e41a9c84a2db7dff48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Tue, 8 Sep 2015 05:20:26 +0200 Subject: [PATCH] Fix missing makeAbsolute --- Language/Haskell/GhcMod/PathsAndFiles.hs | 2 +- Language/Haskell/GhcMod/Utils.hs | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Language/Haskell/GhcMod/PathsAndFiles.hs b/Language/Haskell/GhcMod/PathsAndFiles.hs index 13649c0..228cc87 100644 --- a/Language/Haskell/GhcMod/PathsAndFiles.hs +++ b/Language/Haskell/GhcMod/PathsAndFiles.hs @@ -171,7 +171,7 @@ takeExtension' p = -- it's parent directories. findFileInParentsP :: (FilePath -> Bool) -> FilePath -> IO [(DirPath, [FileName])] -findFileInParentsP p dir' = makeAbsolute dir' >>= \dir -> +findFileInParentsP p dir' = U.makeAbsolute' dir' >>= \dir -> getFilesP p `zipMapM` parents dir -- | @getFilesP p dir@. Find all __files__ satisfying @p@ in @.cabal@ in @dir@. diff --git a/Language/Haskell/GhcMod/Utils.hs b/Language/Haskell/GhcMod/Utils.hs index d4f8043..236f608 100644 --- a/Language/Haskell/GhcMod/Utils.hs +++ b/Language/Haskell/GhcMod/Utils.hs @@ -29,16 +29,13 @@ import qualified Data.Map as M import Data.Maybe (fromMaybe) import Data.Either (rights) import Data.List (inits) -import System.FilePath (joinPath, splitPath, normalise) import Exception import Language.Haskell.GhcMod.Error import Language.Haskell.GhcMod.Types import Language.Haskell.GhcMod.Monad.Types -import System.Directory (getCurrentDirectory, setCurrentDirectory, doesFileExist, - getTemporaryDirectory, canonicalizePath) +import System.Directory import System.Environment -import System.FilePath (splitDrive, takeDirectory, takeFileName, pathSeparators, - (), makeRelative) +import System.FilePath import System.IO.Temp (createTempDirectory) import System.Process (readProcess) import Text.Printf @@ -208,3 +205,17 @@ findFilesWith' f (d:ds) fileName = do files <- findFilesWith' f ds fileName return $ file : files else findFilesWith' f ds fileName + + +-- Copyright : (c) The University of Glasgow 2001 +-- | Make a path absolute by prepending the current directory (if it isn't +-- already absolute) and applying 'normalise' to the result. +-- +-- If the path is already absolute, the operation never fails. Otherwise, the +-- operation may fail with the same exceptions as 'getCurrentDirectory'. +makeAbsolute' :: FilePath -> IO FilePath +makeAbsolute' = (normalise <$>) . absolutize + where absolutize path -- avoid the call to `getCurrentDirectory` if we can + | isRelative path = ( path) . addTrailingPathSeparator <$> + getCurrentDirectory + | otherwise = return path