summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorReto Hablützel <rethab@rethab.ch>2014-03-09 11:05:37 +0100
committerReto Hablützel <rethab@rethab.ch>2014-03-09 11:05:37 +0100
commitb87ed38376361259fb1aa8cef7fd9c34414b98ee (patch)
tree812d335c543c8b1a52a1ce9be56e4cdea104a43c
parentba8a4378e28a3d0986cc3836c67d76cd2da2e1f9 (diff)
downloadxmobar-b87ed38376361259fb1aa8cef7fd9c34414b98ee.tar.gz
xmobar-b87ed38376361259fb1aa8cef7fd9c34414b98ee.tar.bz2
Handle inexistent devices
If a device is unplugged without prior unmounting, it still appears in the /etc/mtab file, which is used for this monitor. The problem is that this monitor canonicalized every path regardless of whether it actually existed or not. I basically added the 'only canonicalize if file exists'.
-rw-r--r--src/Plugins/Monitors/Disk.hs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/Plugins/Monitors/Disk.hs b/src/Plugins/Monitors/Disk.hs
index 73bd5b7..cf4fa00 100644
--- a/src/Plugins/Monitors/Disk.hs
+++ b/src/Plugins/Monitors/Disk.hs
@@ -23,7 +23,8 @@ import Control.Exception (SomeException, handle)
import Control.Monad (zipWithM)
import qualified Data.ByteString.Lazy.Char8 as B
import Data.List (isPrefixOf, find)
-import System.Directory (canonicalizePath)
+import Data.Maybe (catMaybes)
+import System.Directory (canonicalizePath, doesFileExist)
diskIOConfig :: IO MConfig
diskIOConfig = mkMConfig "" ["total", "read", "write",
@@ -40,11 +41,15 @@ type DevDataRef = IORef [(DevName, [Float])]
mountedDevices :: [String] -> IO [(DevName, Path)]
mountedDevices req = do
s <- B.readFile "/etc/mtab"
- parse `fmap` mapM canon (devs s)
+ parse `fmap` mapM mbcanon (devs s)
where
+ mbcanon (d, p) = doesFileExist d >>= \e ->
+ if e
+ then Just `fmap` canon (d,p)
+ else return Nothing
canon (d, p) = do {d' <- canonicalizePath d; return (d', p)}
devs = filter isDev . map (firstTwo . B.words) . B.lines
- parse = map undev . filter isReq
+ parse = map undev . filter isReq . catMaybes
firstTwo (a:b:_) = (B.unpack a, B.unpack b)
firstTwo _ = ("", "")
isDev (d, _) = "/dev/" `isPrefixOf` d