) where
import Prelude hiding ( catch )
+import qualified Prelude
import System.Environment ( getEnv )
import System.FilePath
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 ()
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)
+ ignoreIOExceptions $ 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 ignoreIOExceptions $ hClose hTmp
+ ignoreIOExceptions $ removeFile tmpFPath
bufferSize = 1024
copyContents hFrom hTo buffer = do
when (count > 0) $ do
hPutBuf hTo buffer count
copyContents hFrom hTo buffer
+
+ ignoreIOExceptions io = io `catch` ioExceptionIgnorer
+ ioExceptionIgnorer :: IOException -> IO ()
+ ioExceptionIgnorer _ = return ()
#endif
-- | Given path referring to a file or directory, returns a
-}
doesDirectoryExist :: FilePath -> IO Bool
-doesDirectoryExist name =
- catch
+doesDirectoryExist name =
(withFileStatus "doesDirectoryExist" name $ \st -> isDirectory st)
- (\ _ -> return False)
+ `catch` ((\ _ -> return False) :: IOException -> IO Bool)
{- |The operation 'doesFileExist' returns 'True'
if the argument file exists and is not a directory, and 'False' otherwise.
-}
doesFileExist :: FilePath -> IO Bool
-doesFileExist name = do
- catch
+doesFileExist name =
(withFileStatus "doesFileExist" name $ \st -> do b <- isDirectory st; return (not b))
- (\ _ -> return False)
+ `catch` ((\ _ -> return False) :: IOException -> IO Bool)
{- |The 'getModificationTime' operation returns the
clock time at which the file or directory was last modified.
#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