aboutsummaryrefslogtreecommitdiff
path: root/ch09/ControlledVisit.hs
diff options
context:
space:
mode:
authorJan Sucan <jan@jansucan.com>2023-09-20 15:13:03 +0200
committerJan Sucan <jan@jansucan.com>2023-09-20 15:13:03 +0200
commit360121c45b585839101523638589462cf1c3da6e (patch)
treed71d3a32a662d020a6cf9abca73aa418f7464b8a /ch09/ControlledVisit.hs
parent2e609996237d503ab65c7908e9c5c61fc62553dc (diff)
ch09: Fix compilation errors for a file from the examples
Diffstat (limited to 'ch09/ControlledVisit.hs')
-rw-r--r--ch09/ControlledVisit.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/ch09/ControlledVisit.hs b/ch09/ControlledVisit.hs
index afbff94..9793cdd 100644
--- a/ch09/ControlledVisit.hs
+++ b/ch09/ControlledVisit.hs
@@ -6,12 +6,13 @@ module ControlledVisit
, isDirectory
) where
+import Control.Exception
import Control.Monad (filterM, forM, liftM)
import Data.List (partition)
import Data.Maybe (isJust)
import System.Directory (Permissions(..), getDirectoryContents,
getModificationTime, getPermissions)
-import System.Time (ClockTime(..))
+import Data.Time (UTCTime(..))
import System.FilePath (takeExtension, (</>))
import Control.Exception (bracket, handle)
import System.IO (IOMode(..), hClose, hFileSize, openFile)
@@ -21,7 +22,7 @@ data Info = Info {
infoPath :: FilePath
, infoPerms :: Maybe Permissions
, infoSize :: Maybe Integer
- , infoModTime :: Maybe ClockTime
+ , infoModTime :: Maybe UTCTime
} deriving (Eq, Ord, Show)
getInfo :: FilePath -> IO Info
@@ -29,7 +30,7 @@ getInfo :: FilePath -> IO Info
{-- snippet getInfo --}
maybeIO :: IO a -> IO (Maybe a)
-maybeIO act = handle (\_ -> return Nothing) (Just `liftM` act)
+maybeIO act = handle (\(SomeException _) -> return Nothing) (Just `liftM` act)
getInfo path = do
perms <- maybeIO (getPermissions path)
@@ -39,15 +40,15 @@ getInfo path = do
{-- /snippet getInfo --}
{-- snippet traverse.type --}
-traverse :: ([Info] -> [Info]) -> FilePath -> IO [Info]
+traverse' :: ([Info] -> [Info]) -> FilePath -> IO [Info]
{-- /snippet traverse.type --}
{-- snippet traverse --}
-traverse order path = do
+traverse' order path = do
names <- getUsefulContents path
contents <- mapM getInfo (path : map (path </>) names)
liftM concat $ forM (order contents) $ \info -> do
if isDirectory info && infoPath info /= path
- then traverse order (infoPath info)
+ then traverse' order (infoPath info)
else return [info]
getUsefulContents :: FilePath -> IO [String]