Catch exceptions when finding commands on PATH in Prompt.Shell

This commit is contained in:
Thomas Tuegel
2013-06-16 23:02:19 +00:00
parent 646090a3d9
commit 7958f8905e

View File

@@ -33,7 +33,7 @@ import Codec.Binary.UTF8.String (encodeString)
import Control.Exception as E import Control.Exception as E
import Control.Monad (forM) import Control.Monad (forM)
import Data.List (isPrefixOf) import Data.List (isPrefixOf)
import System.Directory (doesDirectoryExist, getDirectoryContents) import System.Directory (getDirectoryContents)
import System.Environment (getEnv) import System.Environment (getEnv)
import System.Posix.Files (getFileStatus, isDirectory) import System.Posix.Files (getFileStatus, isDirectory)
@@ -113,11 +113,7 @@ getCommands :: IO [String]
getCommands = do getCommands = do
p <- getEnv "PATH" `E.catch` econst [] p <- getEnv "PATH" `E.catch` econst []
let ds = filter (/= "") $ split ':' p let ds = filter (/= "") $ split ':' p
es <- forM ds $ \d -> do es <- forM ds $ \d -> getDirectoryContents d `E.catch` econst []
exists <- doesDirectoryExist d
if exists
then getDirectoryContents d
else return []
return . uniqSort . filter ((/= '.') . head) . concat $ es return . uniqSort . filter ((/= '.') . head) . concat $ es
split :: Eq a => a -> [a] -> [[a]] split :: Eq a => a -> [a] -> [[a]]