+{-# OPTIONS_GHC -w #-}
+-- XXX We get some warnings on Windows
+
-----------------------------------------------------------------------------
-- |
-- Module : System.Directory
) 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 ()
#ifdef __NHC__
copyFile fromFPath toFPath =
do readFile fromFPath >>= writeFile toFPath
- try (copyPermissions fromFPath toFPath)
- return ()
+ Prelude.catch (copyPermissions 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)
+ 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.
getHomeDirectory =
#if defined(mingw32_HOST_OS)
allocaBytes long_path_size $ \pPath -> do
- r <- c_SHGetFolderPath nullPtr csidl_PROFILE nullPtr 0 pPath
- if (r < 0)
+ r0 <- c_SHGetFolderPath nullPtr csidl_PROFILE nullPtr 0 pPath
+ if (r0 < 0)
then do
- r <- c_SHGetFolderPath nullPtr csidl_WINDOWS nullPtr 0 pPath
- when (r < 0) (raiseUnsupported "System.Directory.getHomeDirectory")
+ r1 <- c_SHGetFolderPath nullPtr csidl_WINDOWS nullPtr 0 pPath
+ when (r1 < 0) (raiseUnsupported "System.Directory.getHomeDirectory")
else return ()
peekCString pPath
#else
getTemporaryDirectory = do
#if defined(mingw32_HOST_OS)
allocaBytes long_path_size $ \pPath -> do
- r <- c_GetTempPath (fromIntegral long_path_size) pPath
+ _r <- c_GetTempPath (fromIntegral long_path_size) pPath
peekCString pPath
#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")
+ `Prelude.catch` (\ex -> return "/tmp")
#endif
#endif
foreign import stdcall unsafe "GetTempPathA" c_GetTempPath :: CInt -> CString -> IO CInt
+raiseUnsupported :: String -> IO ()
raiseUnsupported loc =
ioException (IOError Nothing UnsupportedOperation loc "unsupported operation" Nothing)