From 15599771fe4e52e36d7f2496a646fbffb55c7718 Mon Sep 17 00:00:00 2001 From: Juraj Hercek Date: Wed, 28 Jan 2009 17:18:46 +0100 Subject: Workaround for ghc-6.10.1 bug + cleanup Ignore-this: ee8d4e0e29796729d55b90eddf481af1 darcs-hash:20090128161846-69f16-a10f8397ef030ca6ee7be27a24dd6f6252361960.gz --- Plugins/Monitors/CoreCommon.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'Plugins/Monitors/CoreCommon.hs') diff --git a/Plugins/Monitors/CoreCommon.hs b/Plugins/Monitors/CoreCommon.hs index d40b30a..f31ee42 100644 --- a/Plugins/Monitors/CoreCommon.hs +++ b/Plugins/Monitors/CoreCommon.hs @@ -16,6 +16,7 @@ module Plugins.Monitors.CoreCommon where import Plugins.Monitors.Common import System.Posix.Files (fileExist) +import System.IO (withFile, IOMode(ReadMode), hGetLine) import System.Directory import Data.Char (isDigit) import Data.List (isPrefixOf) @@ -26,7 +27,7 @@ import Data.List (isPrefixOf) -- is performed. checkedDataRetrieval :: String -> String -> String -> String -> Double -> Monitor String checkedDataRetrieval failureMessage dir file pattern divisor = do - exists <- io $ fileExist $ foldl (++) dir ["/", pattern, "0/", file] + exists <- io $ fileExist $ concat [dir, "/", pattern, "0/", file] case exists of False -> return failureMessage True -> retrieveData dir file pattern divisor @@ -38,15 +39,16 @@ checkedDataRetrieval failureMessage dir file pattern divisor = do retrieveData :: String -> String -> String -> Double -> Monitor String retrieveData dir file pattern divisor = do count <- io $ dirCount dir pattern - contents <- io $ mapM readFile $ files count + contents <- io $ mapM getGuts $ files count values <- mapM (showWithColors show) $ map conversion contents parseTemplate values where + getGuts file = withFile file ReadMode hGetLine dirCount path str = getDirectoryContents path >>= return . length . filter (\s -> str `isPrefixOf` s && isDigit (last s)) - files count = [ foldl (++) dir [ "/", pattern, show i, "/", file ] - | i <- [0 .. count - 1] ] - conversion = flip (/) divisor . (read :: String -> Double) + files count = map (\i -> concat [dir, "/", pattern, show i, "/", file]) + [0 .. count - 1] + conversion = (/divisor) . (read :: String -> Double) -- cgit v1.2.3