on master help sign in
Merge pull request #1964 from Chobbes/case_sensitivity
16c3c3cEdwin Brady
src/Idris/Imports.hs+22−6
@@ -44,7 +44,7 @@ ibcPath ibcsd use_ibcsd fp = let (d_fp, n_fp) = splitFileName fp
44
44
45ibcPathWithFallback :: FilePath -> FilePath -> IO FilePath
45ibcPathWithFallback :: FilePath -> FilePath -> IO FilePath
46ibcPathWithFallback ibcsd fp = do let ibcp = ibcPath ibcsd True fp
46ibcPathWithFallback ibcsd fp = do let ibcp = ibcPath ibcsd True fp
47− ibc <- doesFileExist ibcp
47+ ibc <- doesFileExist' ibcp
48 return (if ibc
48 return (if ibc
49 then ibcp
49 then ibcp
50 else ibcPath ibcsd False fp)
50 else ibcPath ibcsd False fp)
@@ -58,9 +58,9 @@ findImport (d:ds) ibcsd fp = do let fp_full = d </> fp
58 ibcp <- runIO $ ibcPathWithFallback ibcsd fp_full
58 ibcp <- runIO $ ibcPathWithFallback ibcsd fp_full
59 let idrp = srcPath fp_full
59 let idrp = srcPath fp_full
60 let lidrp = lsrcPath fp_full
60 let lidrp = lsrcPath fp_full
61− ibc <- runIO $ doesFileExist ibcp
61+ ibc <- runIO $ doesFileExist' ibcp
62− idr <- runIO $ doesFileExist idrp
62+ idr <- runIO $ doesFileExist' idrp
63− lidr <- runIO $ doesFileExist lidrp
63+ lidr <- runIO $ doesFileExist' lidrp
64-- when idr $ putStrLn $ idrp ++ " ok"
64-- when idr $ putStrLn $ idrp ++ " ok"
65-- when lidr $ putStrLn $ lidrp ++ " ok"
65-- when lidr $ putStrLn $ lidrp ++ " ok"
66-- when ibc $ putStrLn $ ibcp ++ " ok"
66-- when ibc $ putStrLn $ ibcp ++ " ok"
@@ -78,7 +78,7 @@ findImport (d:ds) ibcsd fp = do let fp_full = d </> fp
78findInPath :: [FilePath] -> FilePath -> IO FilePath
78findInPath :: [FilePath] -> FilePath -> IO FilePath
79findInPath [] fp = fail $ "Can't find file " ++ fp
79findInPath [] fp = fail $ "Can't find file " ++ fp
80findInPath (d:ds) fp = do let p = d </> fp
80findInPath (d:ds) fp = do let p = d </> fp
81− e <- doesFileExist p
81+ e <- doesFileExist' p
82 if e then return p else findInPath ds fp
82 if e then return p else findInPath ds fp
83
83
84findPkgIndex :: String -> Idris FilePath
84findPkgIndex :: String -> Idris FilePath
@@ -94,10 +94,26 @@ installedPackages = do
94 where
94 where
95 allFilesInDir base fp = do
95 allFilesInDir base fp = do
96 let fullpath = base </> fp
96 let fullpath = base </> fp
97− isDir <- doesDirectoryExist fullpath
97+ isDir <- doesDirectoryExist' fullpath
98 if isDir
98 if isDir
99 then fmap concat (mapM (allFilesInDir fullpath) =<< dirContents fullpath)
99 then fmap concat (mapM (allFilesInDir fullpath) =<< dirContents fullpath)
100 else return [fp]
100 else return [fp]
101 dirContents = fmap (filter (not . (`elem` [".", ".."]))) . getDirectoryContents
101 dirContents = fmap (filter (not . (`elem` [".", ".."]))) . getDirectoryContents
102 goodDir idir d = any (".ibc" `isSuffixOf`) <$> allFilesInDir idir d
102 goodDir idir d = any (".ibc" `isSuffixOf`) <$> allFilesInDir idir d
103
103
104+
105+-- Case sensitive file existence check for Mac OS X.
106+doesFileExist' :: FilePath -> IO Bool
107+doesFileExist' = caseSensitive doesFileExist
108+
109+-- Case sensitive directory existence check for Mac OS X.
110+doesDirectoryExist' :: FilePath -> IO Bool
111+doesDirectoryExist' = caseSensitive doesDirectoryExist
112+
113+caseSensitive :: (FilePath -> IO Bool) -> FilePath -> IO Bool
114+caseSensitive existsCheck name =
115+ do exists <- existsCheck name
116+ if exists
117+ then do contents <- getDirectoryContents (takeDirectory name)
118+ return $ (takeFileName name) `elem` contents
119+ else return False