Created
October 31, 2016 08:23
-
-
Save rethab/b95c3a72196da0b57fc96be99da67278 to your computer and use it in GitHub Desktop.
Copy of the function mountedDevices from xmobar's Disk.hs to reproduce problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.ByteString.Lazy.Char8 as B | |
import Data.Maybe (catMaybes) | |
import Data.List (isPrefixOf) | |
import System.Directory (doesFileExist, canonicalizePath) | |
main :: IO () | |
main = mountedDevices ["mapper/home"] >>= print | |
mountedDevices :: [String] -> IO [(String, String)] | |
mountedDevices req = do | |
s <- B.readFile "/etc/mtab" | |
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 . catMaybes | |
firstTwo (a:b:_) = (B.unpack a, B.unpack b) | |
firstTwo _ = ("", "") | |
isDev (d, _) = "/dev/" `isPrefixOf` d | |
isReq (d, p) = p `elem` req || drop 5 d `elem` req | |
undev (d, f) = (drop 5 d, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment