diff options
Diffstat (limited to 'Plugins')
-rw-r--r-- | Plugins/MBox.hs | 17 | ||||
-rw-r--r-- | Plugins/Monitors/Common.hs | 1 | ||||
-rw-r--r-- | Plugins/Monitors/Top.hs | 10 |
3 files changed, 14 insertions, 14 deletions
diff --git a/Plugins/MBox.hs b/Plugins/MBox.hs index 276d50a..8ca0e76 100644 --- a/Plugins/MBox.hs +++ b/Plugins/MBox.hs @@ -15,11 +15,11 @@ module Plugins.MBox (MBox(..)) where import Prelude hiding (catch) -import System.IO import Plugins import Control.Monad import Control.Concurrent.STM +import Control.Exception (SomeException, handle, evaluate) import System.Directory import System.FilePath @@ -45,9 +45,9 @@ instance Exec MBox where ev = [Modify, Create] i <- initINotify - zipWithM_ (\f v -> addWatch i ev f (handle v)) fs vs + zipWithM_ (\f v -> addWatch i ev f (handleNotification v)) fs vs - forM (zip fs vs) $ \(f, v) -> do + forM_ (zip fs vs) $ \(f, v) -> do exists <- doesFileExist f n <- if exists then countMails f else return 0 atomically $ writeTVar v (f, n) @@ -61,12 +61,13 @@ showC m n c = where msg = m ++ show n countMails :: FilePath -> IO Int -countMails f = do - txt <- readFileSafe f - return $ length . filter (isPrefixOf "From ") . lines $ txt +countMails f = + handle ((\_ -> evaluate 0) :: SomeException -> IO Int) + (do txt <- readFileSafe f + evaluate $! length . filter (isPrefixOf "From ") . lines $ txt) -handle :: TVar (FilePath, Int) -> Event -> IO () -handle v _ = do +handleNotification :: TVar (FilePath, Int) -> Event -> IO () +handleNotification v _ = do (p, _) <- atomically $ readTVar v n <- countMails p atomically $ writeTVar v (p, n) diff --git a/Plugins/Monitors/Common.hs b/Plugins/Monitors/Common.hs index 2d35a71..c99a40f 100644 --- a/Plugins/Monitors/Common.hs +++ b/Plugins/Monitors/Common.hs @@ -53,7 +53,6 @@ module Plugins.Monitors.Common ( import Control.Concurrent import Control.Monad.Reader -import Control.Monad (zipWithM) import qualified Data.ByteString.Lazy.Char8 as B import Data.IORef import qualified Data.Map as Map diff --git a/Plugins/Monitors/Top.hs b/Plugins/Monitors/Top.hs index 78ceee9..7e9f072 100644 --- a/Plugins/Monitors/Top.hs +++ b/Plugins/Monitors/Top.hs @@ -102,8 +102,8 @@ type Meminfo = (String, Int) meminfo :: [String] -> Meminfo meminfo fs = (n, r) - where n = processName fs - r = pageSize * (read (fs!!23)) + where !n = processName fs + !r = pageSize * (read (fs!!23)) meminfos :: IO [Meminfo] meminfos = handleProcesses ("", 0) meminfo @@ -132,9 +132,9 @@ type TimesRef = IORef Times timeEntry :: [String] -> TimeEntry timeEntry fs = (p, (n, t)) - where p = read (head fs) - n = processName fs - t = read (fs!!13) + read (fs!!14) + where !p = read (head fs) + !n = processName fs + !t = read (fs!!13) + read (fs!!14) timeEntries :: IO [TimeEntry] timeEntries = handleProcesses (0, ("", 0)) timeEntry |