Commit 205d1bb0 authored by simonmar's avatar simonmar
Browse files

[project @ 2002-02-27 15:16:53 by simonmar]

When searching for files with multiple extensions in multiple paths,
search each path for all the possible files, rather than the other way
around.  Otherwise, a .hs file later in the path may override a .lhs
file earlier in the path, and similar strange things happen with
Reported-by: default avatarDuncan Coutts <>

parent aab07466
......@@ -186,25 +186,18 @@ searchPathExts :: [FilePath]
-> String
-> [(String, FilePath -> String -> IO (Module, ModuleLocation))]
-> IO (Maybe (Module, ModuleLocation))
searchPathExts path basename exts = search exts
searchPathExts path basename exts = search path
search [] = return Nothing
search ((x,f):xs) = do
let fName = (basename ++ '.':x)
found <- findOnPath path fName
case found of
-- special case to avoid getting "./foo.<ext>" all the time
Just "." -> fmap Just (f fName basename)
Just path -> fmap Just (f (path ++ '/':fName)
(path ++ '/':basename))
Nothing -> search xs
findOnPath :: [String] -> String -> IO (Maybe FilePath)
findOnPath path s = loop path
loop [] = return Nothing
loop (d:ds) = do
let file = d ++ '/':s
b <- doesFileExist file
if b then return (Just d) else loop ds
search [] = return Nothing
search (p:ps) = loop exts
base | p == "." = basename
| otherwise = p ++ '/':basename
loop [] = search ps
loop ((ext,fn):exts) = do
let file = base ++ '.':ext
b <- doesFileExist file
if b then Just `liftM` fn file base
else loop exts
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment