From 7df97884eea1b19d7cef9e32b5e2787d0ea5bed7 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 4 Apr 2015 11:14:32 +0900 Subject: re-organise --- src/Utility/Notify/Posix.hs | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Utility/Notify/Posix.hs b/src/Utility/Notify/Posix.hs index 29c9b87..2bfac71 100644 --- a/src/Utility/Notify/Posix.hs +++ b/src/Utility/Notify/Posix.hs @@ -65,26 +65,32 @@ getDBusUserAddress :: IO (Maybe Address) getDBusUserAddress = do -- TODO: catch various IO exceptions! dir <- () <$> getHomeDirectory <*> pure (".dbus" "session-bus") - contents <- getDirectoryContents dir - let realContents = filter (`notElem` [".", ".."]) contents - socketFile <- return realContents - >>= mapM (return . ((dir ++ "/") ++)) - >>= newestFile - + socketFile <- getNewestRealFile dir + -- let realContents = filter (`notElem` [".", ".."]) contents + -- socketFile <- return realContents + -- >>= mapM (return . ((dir ++ "/") ++)) + -- >>= newestFile addr <- readFile socketFile return (return addr >>= parseAddress) -newestFile :: [FilePath] -> IO FilePath -newestFile xs = do - modTimes <- getModTimes xs - let sorted = sortBy (compare `on` snd) modTimes - return $ (fst . head) sorted - --- expects absolute paths -getModTimes :: [FilePath] -> IO [(FilePath, UTCTime)] -getModTimes xs = do - modTimes <- foldM (\ts f -> do; modTime <- getModificationTime f; return (ts ++ [modTime])) [] xs - return $ zip xs modTimes +-- | Return the newest file in a directory, or the empty string if +-- passed a file or empty directory. +getNewestRealFile :: FilePath -> IO FilePath +getNewestRealFile dir = do + + undefined + +-- newestFile :: [FilePath] -> IO FilePath +-- newestFile xs = do +-- modTimes <- getModTimes xs +-- let sorted = sortBy (compare `on` snd) modTimes +-- return $ (fst . head) sorted + +-- -- expects absolute paths +-- getModTimes :: [FilePath] -> IO [(FilePath, UTCTime)] +-- getModTimes xs = do +-- modTimes <- foldM (\ts f -> do; modTime <- getModificationTime f; return (ts ++ [modTime])) [] xs +-- return $ zip xs modTimes -- fixDBusEnvironment :: IO () -- fixDBusEnvironment = do -- cgit v1.2.3