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
mkdependHS.
Reported-by: default avatarDuncan Coutts <duncan.coutts@worcester.oxford.ac.uk>

MERGE TO STABLE
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
where
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
search (p:ps) = loop exts
where
loop [] = return Nothing
loop (d:ds) = do
let file = d ++ '/':s
base | p == "." = basename
| otherwise = p ++ '/':basename
loop [] = search ps
loop ((ext,fn):exts) = do
let file = base ++ '.':ext
b <- doesFileExist file
if b then return (Just d) else loop ds
if b then Just `liftM` fn file base
else loop exts
\end{code}
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