Skip to content

Commit

Permalink
FileManip: migrated to extenible-exceptions
Browse files Browse the repository at this point in the history
--HG--
extra : convert_revision : 65e5f9c80e000fc9680da857ea7a255f3125b614
  • Loading branch information
Sergei Trofimovich committed Mar 5, 2010
1 parent 1a7b99a commit fb34509
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
8 changes: 6 additions & 2 deletions FileManip.cabal
Expand Up @@ -10,20 +10,24 @@ Description: A Haskell library for working with files and directories.
Includes code for pattern matching, finding files,
modifying file contents, and more.
Cabal-version: >= 1.2
Build-type: Simple

Extra-Source-Files: README

Flag splitBase
Description: Choose the new, split-up base package.

Library
if flag(splitBase)
Build-Depends: base, bytestring, directory, filepath, mtl, unix
Build-Depends: base >= 2 && < 5, bytestring, directory, filepath, mtl, unix, extensible-exceptions
else
Build-Depends: base, filepath, mtl, unix
Build-Depends: base >= 2 && < 5, filepath, mtl, unix, extensible-exceptions

GHC-Options: -Wall -O2
Exposed-Modules:
System.FilePath.Find,
System.FilePath.Glob,
System.FilePath.GlobPattern,
System.FilePath.Manip
Other-Modules:
System.FilePath.Error
42 changes: 42 additions & 0 deletions System/FilePath/Error.hs
@@ -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
2 changes: 1 addition & 1 deletion System/FilePath/Find.hs
Expand Up @@ -119,7 +119,7 @@ import System.FilePath ((</>), takeDirectory, takeExtension, takeFileName)
import System.FilePath.GlobPattern (GlobPattern, (~~), (/~))
import System.IO (hPutStrLn, stderr)
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.Types as T

Expand Down
3 changes: 2 additions & 1 deletion System/FilePath/Glob.hs
Expand Up @@ -10,14 +10,15 @@ module System.FilePath.Glob (
namesMatching
) where

import Control.Exception (handle)
import Control.Monad (forM)
import System.FilePath.GlobPattern ((~~))
import System.Directory (doesDirectoryExist, doesFileExist,
getCurrentDirectory, getDirectoryContents)
import System.FilePath (dropTrailingPathSeparator, splitFileName, (</>))
import System.IO.Unsafe (unsafeInterleaveIO)

import System.FilePath.Error (handle)

-- | Return a list of names matching a glob pattern. The list is
-- generated lazily.
namesMatching :: String -> IO [FilePath]
Expand Down
3 changes: 2 additions & 1 deletion System/FilePath/Manip.hs
Expand Up @@ -16,7 +16,8 @@ module System.FilePath.Manip (
, modifyInPlace
) where

import Control.Exception (bracket, bracket_, handle, throwIO)
import System.FilePath.Error (bracket, bracket_, handle, throwIO)

import Control.Monad (liftM)
import Data.Bits ((.&.))
import System.Directory (removeFile)
Expand Down

0 comments on commit fb34509

Please sign in to comment.