FileManip: migrated to extenible-exceptions

This commit is contained in:
Sergei Trofimovich 2010-03-05 21:19:53 +00:00
parent dbdcbd17b1
commit 3d3da401b8
5 changed files with 53 additions and 5 deletions

View file

@ -10,6 +10,8 @@ Description: A Haskell library for working with files and directories.
Includes code for pattern matching, finding files, Includes code for pattern matching, finding files,
modifying file contents, and more. modifying file contents, and more.
Cabal-version: >= 1.2 Cabal-version: >= 1.2
Build-type: Simple
Extra-Source-Files: README Extra-Source-Files: README
Flag splitBase Flag splitBase
@ -17,9 +19,9 @@ Flag splitBase
Library Library
if flag(splitBase) if flag(splitBase)
Build-Depends: base, bytestring, directory, filepath, mtl, unix Build-Depends: base >= 2 && < 5, bytestring, directory, filepath, mtl, unix, extensible-exceptions
else else
Build-Depends: base, filepath, mtl, unix Build-Depends: base >= 2 && < 5, filepath, mtl, unix, extensible-exceptions
GHC-Options: -Wall -O2 GHC-Options: -Wall -O2
Exposed-Modules: Exposed-Modules:
@ -27,3 +29,5 @@ Library
System.FilePath.Glob, System.FilePath.Glob,
System.FilePath.GlobPattern, System.FilePath.GlobPattern,
System.FilePath.Manip System.FilePath.Manip
Other-Modules:
System.FilePath.Error

42
System/FilePath/Error.hs Normal file
View file

@ -0,0 +1,42 @@
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
-- |
-- Module: System.FilePath.Manip
-- Copyright: Sergei Trofimovich
-- License: BSD3
-- Maintainer: Bryan O'Sullivan <bos@serpentine.com>
-- Stability: unstable
-- Portability: Unix-like systems (requires flexible instances)
module System.FilePath.Error
(
bracket
, bracket_
, catch
, handle
, throwIO
, Exception
) where
import qualified Control.Exception.Extensible as EE
import Prelude hiding (catch)
-- we can catch any exceptions if we need to
-- type Exception = SomeException
type Exception = EE.IOException
-- we just pin down 'EE.Exception e' to local Exception
bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket = EE.bracket
bracket_ :: IO a -> IO b -> IO c -> IO c
bracket_ = EE.bracket_
catch :: IO a -> (Exception -> IO a) -> IO a
catch = EE.catch
handle :: (Exception -> IO a) -> IO a -> IO a
handle = EE.handle
throwIO :: (EE.Exception e) => e -> IO a
throwIO = EE.throwIO

View file

@ -119,7 +119,7 @@ import System.FilePath ((</>), takeDirectory, takeExtension, takeFileName)
import System.FilePath.GlobPattern (GlobPattern, (~~), (/~)) import System.FilePath.GlobPattern (GlobPattern, (~~), (/~))
import System.IO (hPutStrLn, stderr) import System.IO (hPutStrLn, stderr)
import System.IO.Unsafe (unsafeInterleaveIO, unsafePerformIO) import System.IO.Unsafe (unsafeInterleaveIO, unsafePerformIO)
import qualified Control.Exception as E import qualified System.FilePath.Error as E
import qualified System.Posix.Files as F import qualified System.Posix.Files as F
import qualified System.Posix.Types as T import qualified System.Posix.Types as T

View file

@ -10,7 +10,6 @@ module System.FilePath.Glob (
namesMatching namesMatching
) where ) where
import Control.Exception (handle)
import Control.Monad (forM) import Control.Monad (forM)
import System.FilePath.GlobPattern ((~~)) import System.FilePath.GlobPattern ((~~))
import System.Directory (doesDirectoryExist, doesFileExist, import System.Directory (doesDirectoryExist, doesFileExist,
@ -18,6 +17,8 @@ import System.Directory (doesDirectoryExist, doesFileExist,
import System.FilePath (dropTrailingPathSeparator, splitFileName, (</>)) import System.FilePath (dropTrailingPathSeparator, splitFileName, (</>))
import System.IO.Unsafe (unsafeInterleaveIO) import System.IO.Unsafe (unsafeInterleaveIO)
import System.FilePath.Error (handle)
-- | Return a list of names matching a glob pattern. The list is -- | Return a list of names matching a glob pattern. The list is
-- generated lazily. -- generated lazily.
namesMatching :: String -> IO [FilePath] namesMatching :: String -> IO [FilePath]

View file

@ -16,7 +16,8 @@ module System.FilePath.Manip (
, modifyInPlace , modifyInPlace
) where ) where
import Control.Exception (bracket, bracket_, handle, throwIO) import System.FilePath.Error (bracket, bracket_, handle, throwIO)
import Control.Monad (liftM) import Control.Monad (liftM)
import Data.Bits ((.&.)) import Data.Bits ((.&.))
import System.Directory (removeFile) import System.Directory (removeFile)