safer-file-handles 0.4 → 0.5
raw patch · 7 files changed
+84/−83 lines, 7 filesdep ~MonadCatchIO-transformersdep ~base-unicode-symbolsdep ~explicit-iomodesPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: MonadCatchIO-transformers, base-unicode-symbols, explicit-iomodes, regions, transformers
API changes (from Hackage documentation)
- System.IO.SaferFileHandles: data A :: *
- System.IO.SaferFileHandles: data R :: *
- System.IO.SaferFileHandles: data RW :: *
- System.IO.SaferFileHandles: data W :: *
+ System.IO.SaferFileHandles: data AppendMode :: *
+ System.IO.SaferFileHandles: data ReadMode :: *
+ System.IO.SaferFileHandles: data ReadWriteMode :: *
+ System.IO.SaferFileHandles: data WriteMode :: *
- System.IO.SaferFileHandles: AppendMode :: IOMode A
+ System.IO.SaferFileHandles: AppendMode :: IOMode AppendMode
- System.IO.SaferFileHandles: ReadMode :: IOMode R
+ System.IO.SaferFileHandles: ReadMode :: IOMode ReadMode
- System.IO.SaferFileHandles: ReadWriteMode :: IOMode RW
+ System.IO.SaferFileHandles: ReadWriteMode :: IOMode ReadWriteMode
- System.IO.SaferFileHandles: TempFile :: Binary -> FilePath -> Template -> DefaultPermissions -> File RW
+ System.IO.SaferFileHandles: TempFile :: Binary -> FilePath -> Template -> DefaultPermissions -> File ReadWriteMode
- System.IO.SaferFileHandles: WriteMode :: IOMode W
+ System.IO.SaferFileHandles: WriteMode :: IOMode WriteMode
- System.IO.SaferFileHandles: openBinaryTempFile :: (MonadCatchIO pr) => FilePath -> Template -> RegionT s pr (FilePath, RegionalFileHandle RW (RegionT s pr))
+ System.IO.SaferFileHandles: openBinaryTempFile :: (MonadCatchIO pr) => FilePath -> Template -> RegionT s pr (FilePath, RegionalFileHandle ReadWriteMode (RegionT s pr))
- System.IO.SaferFileHandles: openBinaryTempFileWithDefaultPermissions :: (MonadCatchIO pr) => FilePath -> Template -> RegionT s pr (FilePath, RegionalFileHandle RW (RegionT s pr))
+ System.IO.SaferFileHandles: openBinaryTempFileWithDefaultPermissions :: (MonadCatchIO pr) => FilePath -> Template -> RegionT s pr (FilePath, RegionalFileHandle ReadWriteMode (RegionT s pr))
- System.IO.SaferFileHandles: openTempFile :: (MonadCatchIO pr) => FilePath -> Template -> RegionT s pr (FilePath, RegionalFileHandle RW (RegionT s pr))
+ System.IO.SaferFileHandles: openTempFile :: (MonadCatchIO pr) => FilePath -> Template -> RegionT s pr (FilePath, RegionalFileHandle ReadWriteMode (RegionT s pr))
- System.IO.SaferFileHandles: openTempFileWithDefaultPermissions :: (MonadCatchIO pr) => FilePath -> Template -> RegionT s pr (FilePath, RegionalFileHandle RW (RegionT s pr))
+ System.IO.SaferFileHandles: openTempFileWithDefaultPermissions :: (MonadCatchIO pr) => FilePath -> Template -> RegionT s pr (FilePath, RegionalFileHandle ReadWriteMode (RegionT s pr))
Files
- Data/ByteString/Char8/SaferFileHandles.hs +2/−2
- Data/ByteString/Lazy/Char8/SaferFileHandles.hs +2/−2
- Data/ByteString/Lazy/SaferFileHandles.hs +2/−2
- Data/ByteString/SaferFileHandles.hs +2/−2
- System/IO/SaferFileHandles.hs +51/−37
- System/IO/SaferFileHandles/Internal.hs +17/−16
- safer-file-handles.cabal +8/−22
Data/ByteString/Char8/SaferFileHandles.hs view
@@ -3,7 +3,7 @@ ------------------------------------------------------------------------------- -- | -- Module : Data.ByteString.SaferFileHandles--- Copyright : (c) 2009 Bas van Dijk+-- Copyright : (c) 2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> --@@ -30,7 +30,7 @@ import Data.Int ( Int ) -- from transformers:-import Control.Monad.Trans ( MonadIO )+import Control.Monad.IO.Class ( MonadIO ) -- from bytestring: import qualified Data.ByteString.Char8 as B
Data/ByteString/Lazy/Char8/SaferFileHandles.hs view
@@ -3,7 +3,7 @@ ------------------------------------------------------------------------------- -- | -- Module : Data.ByteString.SaferFileHandles--- Copyright : (c) 2009 Bas van Dijk+-- Copyright : (c) 2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> --@@ -27,7 +27,7 @@ import Data.Int ( Int ) -- from transformers:-import Control.Monad.Trans ( MonadIO )+import Control.Monad.IO.Class ( MonadIO ) -- from bytestring: import qualified Data.ByteString.Lazy.Char8 as B
Data/ByteString/Lazy/SaferFileHandles.hs view
@@ -3,7 +3,7 @@ ------------------------------------------------------------------------------- -- | -- Module : Data.ByteString.SaferFileHandles--- Copyright : (c) 2009 Bas van Dijk+-- Copyright : (c) 2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> --@@ -28,7 +28,7 @@ import Data.Int ( Int ) -- from transformers:-import Control.Monad.Trans ( MonadIO )+import Control.Monad.IO.Class ( MonadIO ) -- from bytestring: import qualified Data.ByteString.Lazy as B
Data/ByteString/SaferFileHandles.hs view
@@ -3,7 +3,7 @@ ------------------------------------------------------------------------------- -- | -- Module : Data.ByteString.SaferFileHandles--- Copyright : (c) 2009 Bas van Dijk+-- Copyright : (c) 2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> --@@ -30,7 +30,7 @@ import Data.Int ( Int ) -- from transformers:-import Control.Monad.Trans ( MonadIO )+import Control.Monad.IO.Class ( MonadIO ) -- from bytestring: import qualified Data.ByteString as B
System/IO/SaferFileHandles.hs view
@@ -1,16 +1,13 @@ {-# LANGUAGE UnicodeSyntax , NoImplicitPrelude , CPP- , GADTs- , TypeFamilies , RankNTypes- , MultiParamTypeClasses #-} ------------------------------------------------------------------------------- -- | -- Module : System.IO.SaferFileHandles--- Copyright : (c) 2009 Bas van Dijk+-- Copyright : (c) 2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> --@@ -26,9 +23,9 @@ -- which allows it to be used with the @regions@ package. The @regions@ package -- provides the region monad transformer 'RegionT'. Scarce resources, like files -- for example, can be opened in a region. When the region terminates, all--- opened resources will be automatically closed. The main advantage of regions+-- opened resources will be closed automatically. The main advantage of regions -- is that the handles to the opened resources can not be returned from the--- region which ensures no I/O with closed resources is possible. The primary+-- region. This ensures no I/O with closed resources is possible. The primary -- technique used in @regions@ is called \"Lightweight monadic regions\" which -- was invented by Oleg Kiselyov and Chung-chieh Shan. See: -- <http://okmij.org/ftp/Haskell/regions.html#light-weight>@@ -63,15 +60,24 @@ ( -- * Files with explicit IO modes as scarce resources File(..) , Binary- , FilePath+ , Template+#if MIN_VERSION_base(4,2,0)+ , DefaultPermissions+#endif -- ** IO Modes -- | Types that represent the IOMode an opened file can be in.- , R, W, A, RW+ , IOMode(..) - , ReadModes, WriteModes+ , ReadMode+ , WriteMode+ , AppendMode+ , ReadWriteMode + , ReadModes+ , WriteModes+ -- ** Opening files in a region {-| Note that this module re-exports the @Control.Monad.Trans.Region@@@ -91,8 +97,6 @@ , openFile, withFile - , IOMode(..)- -- * Operations on regional file handles -- ** Determining and changing the size of a file , hFileSize@@ -184,11 +188,6 @@ #endif -- * Temporary files-#if MIN_VERSION_base(4,2,0)- , DefaultPermissions-#endif- , Template- , openTempFile , openBinaryTempFile @@ -228,8 +227,7 @@ -- from base: import Prelude ( Integer )-import Control.Monad ( return, (>>=), fail- )+import Control.Monad ( return, (>>=), fail ) import Data.Function ( ($) ) import Data.Bool ( Bool(False, True) ) import Data.Char ( Char, String )@@ -248,7 +246,7 @@ import Control.Monad.CatchIO ( MonadCatchIO ) -- from transformers:-import Control.Monad.Trans ( MonadIO, liftIO )+import Control.Monad.IO.Class ( MonadIO, liftIO ) -- from regions: import Control.Monad.Trans.Region -- (re-exported entirely)@@ -260,10 +258,14 @@ -- from explicit-iomodes import System.IO.ExplicitIOModes ( IOMode(..)- , R, W, A, RW++ , ReadMode+ , WriteMode+ , AppendMode+ , ReadWriteMode+ , ReadModes , WriteModes- -- TODO:, CheckMode , FilePath , BufferMode(..)@@ -289,16 +291,16 @@ import qualified System.IO.ExplicitIOModes as E -- from ourselves:-import System.IO.SaferFileHandles.Internal---- TODO: explicit import:--- import System.IO.SaferFileHandles.Internal ( RegionalFileHandle--- , File(..)--- , Binary--- , Template--- , Standard(..)--- , wrap, wrap2, wrap3--- )+import System.IO.SaferFileHandles.Internal ( RegionalFileHandle+ , File(..)+ , Binary+ , Template+#if MIN_VERSION_base(4,2,0)+ , DefaultPermissions+#endif+ , mbFilePath+ , wrap, wrap2, wrap3+ ) -------------------------------------------------------------------------------@@ -643,7 +645,9 @@ ⇒ Binary → FilePath → Template- → RegionT s pr (FilePath, RegionalFileHandle RW (RegionT s pr))+ → RegionT s pr ( FilePath+ , RegionalFileHandle ReadWriteMode (RegionT s pr)+ ) genOpenTempFile binary filePath template = do rh ← open $ TempFile binary filePath template #if MIN_VERSION_base(4,2,0)@@ -660,7 +664,9 @@ openTempFile ∷ MonadCatchIO pr ⇒ FilePath → Template- → RegionT s pr (FilePath, RegionalFileHandle RW (RegionT s pr))+ → RegionT s pr ( FilePath+ , RegionalFileHandle ReadWriteMode (RegionT s pr)+ ) openTempFile = genOpenTempFile False -- | Open a temporary file in binary mode yielding a regional handle to it@@ -670,7 +676,9 @@ MonadCatchIO pr ⇒ FilePath → Template- → RegionT s pr (FilePath, RegionalFileHandle RW (RegionT s pr))+ → RegionT s pr ( FilePath+ , RegionalFileHandle ReadWriteMode (RegionT s pr)+ ) openBinaryTempFile = genOpenTempFile True #if MIN_VERSION_base(4,2,0)@@ -679,7 +687,9 @@ ⇒ Binary → FilePath → Template- → RegionT s pr (FilePath, RegionalFileHandle RW (RegionT s pr))+ → RegionT s pr ( FilePath+ , RegionalFileHandle ReadWriteMode (RegionT s pr)+ ) genOpenTempFileWithDefaultPermissions binary filePath template = do rh ← open $ TempFile binary filePath template True return (generatedFilePath rh, rh)@@ -691,7 +701,9 @@ MonadCatchIO pr ⇒ FilePath → Template- → RegionT s pr (FilePath, RegionalFileHandle RW (RegionT s pr))+ → RegionT s pr ( FilePath+ , RegionalFileHandle ReadWriteMode (RegionT s pr)+ ) openTempFileWithDefaultPermissions = genOpenTempFileWithDefaultPermissions False -- | Open a temporary file in binary mode with default permissions yielding a@@ -702,7 +714,9 @@ MonadCatchIO pr ⇒ FilePath → Template- → RegionT s pr (FilePath, RegionalFileHandle RW (RegionT s pr))+ → RegionT s pr ( FilePath+ , RegionalFileHandle ReadWriteMode (RegionT s pr)+ ) openBinaryTempFileWithDefaultPermissions = genOpenTempFileWithDefaultPermissions True #endif
System/IO/SaferFileHandles/Internal.hs view
@@ -3,14 +3,12 @@ , CPP , GADTs , TypeFamilies- , RankNTypes- , MultiParamTypeClasses #-} ------------------------------------------------------------------------------- -- | -- Module : System.IO.Internal--- Copyright : (c) 2009 Bas van Dijk+-- Copyright : (c) 2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> --@@ -19,8 +17,8 @@ module System.IO.SaferFileHandles.Internal where -- from base:-import Control.Applicative ( (<$>) ) import Data.Function ( ($) )+import Data.Functor ( (<$>) ) import Data.Tuple ( uncurry ) import Data.Bool ( Bool(False, True) ) import Data.Char ( String )@@ -32,16 +30,19 @@ import Data.Function.Unicode ( (∘) ) -- from transformers:-import Control.Monad.Trans ( MonadIO, liftIO )+import Control.Monad.IO.Class ( MonadIO, liftIO ) -- from regions:-import Control.Resource ( Resource, openResource, closeResource )-import qualified Control.Resource as R ( Handle )+import Control.Resource ( Resource, Handle, open, close ) import Control.Monad.Trans.Region ( RegionalHandle ) import Control.Monad.Trans.Region.Unsafe ( internalHandle ) +#if __HADDOCK__+import qualified Control.Monad.Trans.Region as Region ( open )+#endif+ -- from explicit-iomodes-import System.IO.ExplicitIOModes ( IOMode(..), RW, IO, FilePath )+import System.IO.ExplicitIOModes ( IOMode(..), ReadWriteMode, IO, FilePath ) import qualified System.IO.ExplicitIOModes as E ( Handle@@ -65,7 +66,7 @@ open the file. Note that this module provides an instance for 'Resource' for 'File'-@ioMode@. This allows you to 'open' files in a region which are automatically+@ioMode@. This allows you to 'Region.open' files in a region which are automatically closed when the region terminates but it disallows you to return handles to these closed files from the region so preventing I/O with closed files. -}@@ -77,7 +78,7 @@ #if MIN_VERSION_base(4,2,0) → DefaultPermissions #endif- → File RW+ → File ReadWriteMode -- | Should the file be opened in binary mode? type Binary = Bool@@ -91,7 +92,7 @@ #endif instance Resource (File ioMode) where- data R.Handle (File ioMode) =+ data Handle (File ioMode) = FileHandle { mbFilePath ∷ Maybe FilePath -- ^ Get the optional file path. This is needed because -- opening a temporary file also yields the generated file@@ -99,13 +100,13 @@ , handle ∷ E.Handle ioMode } - openResource (File isBinary filePath ioMode) =+ open (File isBinary filePath ioMode) = FileHandle Nothing <$> (if isBinary then E.openBinaryFile else E.openFile) filePath ioMode #if MIN_VERSION_base(4,2,0)- openResource (TempFile isBinary filePath template defaultPerms) = do+ open (TempFile isBinary filePath template defaultPerms) = uncurry (FileHandle ∘ Just) <$> (case (isBinary, defaultPerms) of (False, False) → E.openTempFile@@ -114,12 +115,12 @@ (True, True) → E.openBinaryTempFileWithDefaultPermissions ) filePath template #else- openResource (TempFile isBinary filePath template) = do+ open (TempFile isBinary filePath template) = uncurry (FileHandle ∘ Just) <$> (if isBinary then E.openBinaryTempFile else E.openTempFile) filePath template #endif- closeResource = sanitizeIOError ∘ E.hClose ∘ handle+ close = sanitizeIOError ∘ E.hClose ∘ handle -- | A handy type synonym for a regional handle to an opened file parameterized -- by the 'IOMode' in which you opened the file and the region in which it was@@ -150,7 +151,7 @@ wrap3 f = \h z y → liftIO $ sanitizeIOError $ f (regularHandle h) z y sanitizeIOError ∷ IO α → IO α-sanitizeIOError = modifyIOError $ \e -> e { ioe_handle = Nothing }+sanitizeIOError = modifyIOError $ \e → e { ioe_handle = Nothing } -- The End ---------------------------------------------------------------------
safer-file-handles.cabal view
@@ -1,5 +1,5 @@ name: safer-file-handles-version: 0.4+version: 0.5 cabal-version: >=1.6 build-type: Custom license: BSD3@@ -12,45 +12,31 @@ synopsis: Type-safe file handling description: This package adds two safety features on top of the regular @System.IO@ file handles and operations:- .- * Regional file handles. Files must be opened in a /region/. When the region terminates all opened files are automatically closed. The main advantage of regions is that the handles to the opened files can not be returned from the region which ensures no I/O with closed files is possible.- .- * Explicit IOModes. The regional file handles are parameterized by the IOMode in which they were opened. All operations on handles explicitly specify the needed IOMode. This way it is impossible to read from a write-only handle or write to a read-only handle for example.- .- The primary technique used in this package is called \"Lightweight monadic regions\" which was invented by Oleg Kiselyov and Chung-chieh Shan. See:- .- <http://okmij.org/ftp/Haskell/regions.html#light-weight>- .- This technique is implemented in the @regions@ package which is re-exported from @safer-file-handles@.- .- See the @safer-file-handles-examples@ package for examples how to use this package:- .- darcs get <http://code.haskell.org/~basvandijk/code/safer-file-handles-examples> source-repository head@@ -59,13 +45,13 @@ Library GHC-Options: -Wall- build-depends: base >= 4 && < 4.3- , base-unicode-symbols >= 0.1.1 && < 0.2- , bytestring == 0.9.*- , regions == 0.4.*- , transformers >= 0.1.4 && < 0.2- , MonadCatchIO-transformers >= 0.0.2.0 && < 0.1- , explicit-iomodes == 0.2.*+ build-depends: base >= 4 && < 4.3+ , base-unicode-symbols >= 0.1.1 && < 0.3+ , bytestring >= 0.9 && < 0.10+ , regions >= 0.5 && < 0.6+ , transformers >= 0.2 && < 0.3+ , MonadCatchIO-transformers >= 0.2 && < 0.3+ , explicit-iomodes >= 0.3 && < 0.4 exposed-modules: System.IO.SaferFileHandles Data.ByteString.SaferFileHandles