1{-# LANGUAGE CPP #-} 2 3module Distribution.Compat.Directory 4( listDirectory 5, makeAbsolute 6, doesPathExist 7) where 8 9#if MIN_VERSION_directory(1,2,7) 10import System.Directory as Dir hiding (doesPathExist) 11import System.Directory (doesPathExist) 12#else 13import System.Directory as Dir 14#endif 15#if !MIN_VERSION_directory(1,2,2) 16import System.FilePath as Path 17#endif 18 19#if !MIN_VERSION_directory(1,2,5) 20 21listDirectory :: FilePath -> IO [FilePath] 22listDirectory path = 23 filter f `fmap` Dir.getDirectoryContents path 24 where f filename = filename /= "." && filename /= ".." 25 26#endif 27 28#if !MIN_VERSION_directory(1,2,2) 29 30makeAbsolute :: FilePath -> IO FilePath 31makeAbsolute p | Path.isAbsolute p = return p 32 | otherwise = do 33 cwd <- Dir.getCurrentDirectory 34 return $ cwd </> p 35 36#endif 37 38#if !MIN_VERSION_directory(1,2,7) 39 40doesPathExist :: FilePath -> IO Bool 41doesPathExist path = do 42 -- not using Applicative, as this way we can do less IO 43 e <- doesDirectoryExist path 44 if e 45 then return True 46 else doesFileExist path 47 48#endif 49 50