From 833d9ce058559aec3b1136ebe2fe64790ff77afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Mon, 3 Nov 2014 00:04:15 +0100 Subject: [PATCH] $HOME/.cabal is not a cabal file --- Language/Haskell/GhcMod/PathsAndFiles.hs | 13 +++++++++++-- test/PathsAndFilesSpec.hs | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Language/Haskell/GhcMod/PathsAndFiles.hs b/Language/Haskell/GhcMod/PathsAndFiles.hs index 08bff0d..ccd0acf 100644 --- a/Language/Haskell/GhcMod/PathsAndFiles.hs +++ b/Language/Haskell/GhcMod/PathsAndFiles.hs @@ -30,7 +30,7 @@ type FileName = String -- or 'GMETooManyCabalFiles' findCabalFiles :: FilePath -> IO (Maybe FilePath) findCabalFiles directory = do - -- Look for cabal files in all parent directories of @dir@ + -- Look for cabal files in @dir@ and all it's parent directories dcs <- getCabalFiles `zipMapM` parents directory -- Extract first non-empty list, which represents a directory with cabal -- files. @@ -42,7 +42,16 @@ findCabalFiles directory = do -- | @getCabalFiles dir@. Find all files ending in @.cabal@ in @dir@. getCabalFiles :: DirPath -> IO [FileName] getCabalFiles dir = - filter ((==) ".cabal" . takeExtension) <$> getDirectoryContents dir + filterM isCabalFile =<< getDirectoryContents dir + where + isCabalFile f = do + exists <- doesFileExist f + return (exists && takeExtension' f == ".cabal") + + takeExtension' p = if takeFileName p == takeExtension p + then "" + else takeExtension p + makeAbsolute :: DirPath -> [FileName] -> [FilePath] makeAbsolute dir fs = (dir ) `map` fs diff --git a/test/PathsAndFilesSpec.hs b/test/PathsAndFilesSpec.hs index aa46f12..aa2a253 100644 --- a/test/PathsAndFilesSpec.hs +++ b/test/PathsAndFilesSpec.hs @@ -8,6 +8,7 @@ import Language.Haskell.GhcMod.GhcPkg #endif import System.Directory +import System.Environment import System.FilePath (()) import Test.Hspec @@ -28,3 +29,7 @@ spec = do it "returns Nothing if the sandbox config file is broken" $ do getSandboxDb "test/data/broken-sandbox" `shouldReturn` Nothing + + describe "getCabalFiles" $ do + it "doesn't think $HOME/.cabal is a cabal file" $ do + (getCabalFiles =<< getEnv "HOME") `shouldReturn` []