diff options
Diffstat (limited to 'ghc/compiler/utils')
-rw-r--r-- | ghc/compiler/utils/Util.lhs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ghc/compiler/utils/Util.lhs b/ghc/compiler/utils/Util.lhs index d51a09d9ab..2f20226794 100644 --- a/ghc/compiler/utils/Util.lhs +++ b/ghc/compiler/utils/Util.lhs @@ -56,6 +56,7 @@ module Util ( -- IO-ish utilities createDirectoryHierarchy, doesDirNameExist, + modificationTimeIfExists, later, handleDyn, handle, @@ -89,10 +90,12 @@ import List ( zipWith4 ) #endif import Monad ( when ) -import IO ( catch ) +import IO ( catch, isDoesNotExistError ) import Directory ( doesDirectoryExist, createDirectory ) import Char ( isUpper, isAlphaNum, isSpace, ord, isDigit ) import Ratio ( (%) ) +import Time ( ClockTime ) +import Directory ( getModificationTime ) infixr 9 `thenCmp` \end{code} @@ -840,6 +843,16 @@ handle h f = f `Exception.catch` \e -> case e of #endif -- -------------------------------------------------------------- +-- check existence & modification time at the same time + +modificationTimeIfExists :: FilePath -> IO (Maybe ClockTime) +modificationTimeIfExists f = do + (do t <- getModificationTime f; return (Just t)) + `IO.catch` \e -> if isDoesNotExistError e + then return Nothing + else ioError e + +-- -------------------------------------------------------------- -- Filename manipulation type Suffix = String |