findModule, -- :: ModuleName -> IO (Maybe (Module, ModuleLocation))
mkHomeModuleLocn, -- :: ModuleName -> String -> FilePath
-- -> IO ModuleLocation
- emptyHomeDirCache -- :: IO ()
+ emptyHomeDirCache, -- :: IO ()
+ flushPackageCache -- :: [PackageConfig] -> IO ()
) where
#include "HsVersions.h"
import Config
import IOExts
-import Directory
import List
import IO
import Monad
initFinder :: [PackageConfig] -> IO ()
initFinder pkgs
- = do { -- expunge our home cache
- ; writeIORef v_HomeDirCache Nothing
- -- lazilly fill in the package cache
- ; writeIORef v_PkgDirCache (unsafePerformIO (newPkgCache pkgs))
- }
+ = do emptyHomeDirCache
+ flushPackageCache pkgs
+
+-- empty, and lazilly fill in the package cache
+flushPackageCache :: [PackageConfig] -> IO ()
+flushPackageCache pkgs = writeIORef v_PkgDirCache
+ (unsafePerformIO (newPkgCache pkgs))
emptyHomeDirCache :: IO ()
-emptyHomeDirCache
- = writeIORef v_HomeDirCache Nothing
+emptyHomeDirCache = writeIORef v_HomeDirCache Nothing
findModule :: ModuleName -> IO (Maybe (Module, ModuleLocation))
findModule name
-- to ["."]).
home_imports <- readIORef v_Import_paths
let extendFM fm path = do
- contents <- getDirectoryContents' path
+ contents <- softGetDirectoryContents path
let clean_contents = filter isUsefulFile contents
return (addListToFM fm (zip clean_contents (repeat path)))
- home_map <- foldM extendFM emptyFM home_imports
+ home_map <- foldM extendFM emptyFM (reverse home_imports)
writeIORef v_HomeDirCache (Just home_map)
return home_map
let dirs = import_dirs pkg
pkg_name = _PK_ (name pkg)
let addDir fm dir = do
- contents <- getDirectoryContents' dir
+ contents <- softGetDirectoryContents dir
return (addListToFM fm (zip contents
(repeat (pkg_name,dir))))
foldM addDir fm dirs
isUsefulFile fn
= let suffix = (reverse . takeWhile (/= '.') . reverse) fn
in suffix `elem` ["hi", "hs", "lhs", "hi-boot", "hi-boot-5"]
-
-getDirectoryContents' d
- = IO.catch (getDirectoryContents d)
- (\_ -> do hPutStr stderr
- ("WARNING: error while reading directory " ++ d)
- return []
- )
-
\end{code}