From 1e5361634268e81dfa56c87e2c2f0342d4314e81 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Mon, 23 Jun 2008 19:31:05 +0000 Subject: [PATCH] Follow extensible exceptions changes --- System/Directory.hs | 23 ++++++++++------------- tests/copyFile001.hs | 2 +- tests/copyFile002.hs | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/System/Directory.hs b/System/Directory.hs index 800816f..5298322 100644 --- a/System/Directory.hs +++ b/System/Directory.hs @@ -70,6 +70,7 @@ module System.Directory ) where import Prelude hiding ( catch ) +import qualified Prelude import System.Environment ( getEnv ) import System.FilePath @@ -368,7 +369,7 @@ removeDirectoryRecursive startLoc = do case temp of Left e -> do isDir <- doesDirectoryExist f -- If f is not a directory, re-throw the error - unless isDir $ throw e + unless isDir $ throw (e :: SomeException) removeDirectoryRecursive f Right _ -> return () @@ -548,19 +549,16 @@ copyFile fromFPath toFPath = return () #else copyFile fromFPath toFPath = - copy `catch` (\e -> case e of - IOException exc -> - throw $ IOException $ ioeSetLocation exc "copyFile" - _ -> throw e) + copy `Prelude.catch` (\exc -> throw $ ioeSetLocation exc "copyFile") where copy = bracket (openBinaryFile fromFPath ReadMode) hClose $ \hFrom -> bracketOnError openTmp cleanTmp $ \(tmpFPath, hTmp) -> do allocaBytes bufferSize $ copyContents hFrom hTmp hClose hTmp - try (copyPermissions fromFPath tmpFPath) + ignoreExceptions $ copyPermissions fromFPath tmpFPath renameFile tmpFPath toFPath openTmp = openBinaryTempFile (takeDirectory toFPath) ".copyFile.tmp" - cleanTmp (tmpFPath, hTmp) = do try $ hClose hTmp - try $ removeFile tmpFPath + cleanTmp (tmpFPath, hTmp) = do ignoreExceptions $ hClose hTmp + ignoreExceptions $ removeFile tmpFPath bufferSize = 1024 copyContents hFrom hTo buffer = do @@ -809,7 +807,7 @@ exists and is a directory, and 'False' otherwise. doesDirectoryExist :: FilePath -> IO Bool doesDirectoryExist name = - catch + catchAny (withFileStatus "doesDirectoryExist" name $ \st -> isDirectory st) (\ _ -> return False) @@ -819,7 +817,7 @@ if the argument file exists and is not a directory, and 'False' otherwise. doesFileExist :: FilePath -> IO Bool doesFileExist name = do - catch + catchAny (withFileStatus "doesFileExist" name $ \st -> do b <- isDirectory st; return (not b)) (\ _ -> return False) @@ -1034,9 +1032,8 @@ getTemporaryDirectory = do #else getEnv "TMPDIR" #if !__NHC__ - `catch` \ex -> case ex of - IOException e | isDoesNotExistError e -> return "/tmp" - _ -> throw ex + `Prelude.catch` \e -> if isDoesNotExistError e then return "/tmp" + else throw e #else `catch` (\ex -> return "/tmp") #endif diff --git a/tests/copyFile001.hs b/tests/copyFile001.hs index 219b01b..e279dd0 100644 --- a/tests/copyFile001.hs +++ b/tests/copyFile001.hs @@ -7,7 +7,7 @@ import System.Directory import System.IO main :: IO () -main = do try $ removeFile to +main = do ignoreExceptions $ removeFile to cs_before <- getDirectoryContents "copyFile" putStrLn "Before:" print $ sort cs_before diff --git a/tests/copyFile002.hs b/tests/copyFile002.hs index 332d762..ff42d67 100644 --- a/tests/copyFile002.hs +++ b/tests/copyFile002.hs @@ -12,7 +12,7 @@ main :: IO () main = do d <- getCurrentDirectory flip finally (setCurrentDirectory d) $ do setCurrentDirectory "copyFile" - try $ removeFile to + ignoreExceptions $ removeFile to cs_before <- getDirectoryContents "." putStrLn "Before:" print $ sort cs_before -- 1.7.10.4