don't fail when PATH contains bad directories

This commit is contained in:
Simon Michael 2011-08-25 23:36:25 +00:00
parent 7616ed9b8e
commit ec9e06e33e

View File

@ -342,11 +342,13 @@ getHledgerAddonCommands = map (drop (length progname + 1)) `fmap` getHledgerProg
getHledgerProgramsInPath :: IO [String]
getHledgerProgramsInPath = do
pathdirs <- splitOn ":" `fmap` getEnv "PATH"
pathexes <- concat `fmap` mapM getDirectoryContents pathdirs
pathexes <- concat `fmap` mapM getDirectoryContentsSafe pathdirs
return $ nub $ sort $ filter (isRight . parsewith hledgerprog) pathexes
where
hledgerprog = string progname >> char '-' >> many1 (letter <|> char '-') >> eof
getDirectoryContentsSafe d = getDirectoryContents d `catch` (\_ -> return [])
-- | Convert possibly encoded option values to regular unicode strings.
decodeRawOpts = map (\(name,val) -> (name, fromPlatformString val))