@@ -6,7 +6,6 @@ module System.FS.BlockIO.API (
66 HasBlockIO (.. )
77 , IOCtxParams (.. )
88 , defaultIOCtxParams
9- , mkClosedError
109 , IOOp (.. )
1110 , ioopHandle
1211 , ioopFileOffset
@@ -25,18 +24,14 @@ module System.FS.BlockIO.API (
2524 -- ** Storage synchronisation
2625 , synchroniseFile
2726 , synchroniseDirectoryRecursive
28- -- * Defaults for the real file system
29- , tryLockFileIO
30- , createHardLinkIO
3127 -- * Re-exports
3228 , ByteCount
3329 , FileOffset
3430 ) where
3531
3632import Control.DeepSeq
3733import Control.Monad (forM_ )
38- import Control.Monad.Class.MonadThrow (MonadCatch (bracketOnError ),
39- MonadThrow (.. ), bracketOnError , try )
34+ import Control.Monad.Class.MonadThrow (MonadThrow (.. ))
4035import Control.Monad.Primitive (PrimMonad (PrimState ))
4136import Data.Primitive.ByteArray (MutableByteArray )
4237import qualified Data.Vector as V
@@ -45,15 +40,10 @@ import qualified Data.Vector.Generic.Mutable as VGM
4540import qualified Data.Vector.Primitive as VP
4641import qualified Data.Vector.Unboxed as VU
4742import qualified Data.Vector.Unboxed.Mutable as VUM
48- import GHC.IO.Exception (IOErrorType (ResourceVanished ))
4943import qualified GHC.IO.Handle.Lock as GHC
5044import GHC.Stack (HasCallStack )
5145import qualified System.FS.API as FS
52- import System.FS.API (BufferOffset , FsError (.. ), FsPath , Handle (.. ),
53- HasFS , SomeHasFS (.. ))
54- import System.FS.IO (HandleIO )
55- import qualified System.IO as GHC
56- import System.IO.Error (ioeSetErrorString , mkIOError )
46+ import System.FS.API (BufferOffset , FsPath , Handle (.. ), HasFS )
5747import System.Posix.Types (ByteCount , FileOffset )
5848import Text.Printf
5949
@@ -180,14 +170,6 @@ defaultIOCtxParams = IOCtxParams {
180170 ioctxConcurrencyLimit = 64 * 3
181171 }
182172
183- mkClosedError :: HasCallStack => SomeHasFS m -> String -> FsError
184- mkClosedError (SomeHasFS hasFS) loc = FS. ioToFsError (FS. mkFsErrorPath hasFS (FS. mkFsPath [] )) ioerr
185- where ioerr =
186- ioeSetErrorString
187- (mkIOError ResourceVanished loc Nothing Nothing )
188- (" HasBlockIO closed: " <> loc)
189-
190-
191173data IOOp s h =
192174 IOOpRead ! (Handle h ) ! FileOffset ! (MutableByteArray s ) ! BufferOffset ! ByteCount
193175 | IOOpWrite ! (Handle h ) ! FileOffset ! (MutableByteArray s ) ! BufferOffset ! ByteCount
@@ -300,42 +282,3 @@ newtype LockFileHandle m = LockFileHandle {
300282 -- | Release a file lock acquired using 'tryLockFile'.
301283 hUnlock :: m ()
302284 }
303-
304- tryLockFileIO :: HasFS IO HandleIO -> FsPath -> GHC. LockMode -> IO (Maybe (LockFileHandle IO ))
305- tryLockFileIO hfs fsp mode = do
306- fp <- FS. unsafeToFilePath hfs fsp -- shouldn't fail because we are in IO
307- rethrowFsErrorIO hfs fsp $
308- bracketOnError (GHC. openFile fp GHC. WriteMode ) GHC. hClose $ \ h -> do
309- bracketOnError (GHC. hTryLock h mode) (\ _ -> GHC. hUnlock h) $ \ b -> do
310- if b then
311- pure $ Just LockFileHandle { hUnlock = rethrowFsErrorIO hfs fsp $ do
312- GHC. hUnlock h
313- `finally` GHC. hClose h
314- }
315- else
316- pure $ Nothing
317-
318- -- This is copied/adapted from System.FS.IO
319- rethrowFsErrorIO :: HasCallStack => HasFS IO HandleIO -> FsPath -> IO a -> IO a
320- rethrowFsErrorIO hfs fp action = do
321- res <- try action
322- case res of
323- Left err -> handleError err
324- Right a -> pure a
325- where
326- handleError :: HasCallStack => IOError -> IO a
327- handleError ioErr =
328- throwIO $ FS. ioToFsError (FS. mkFsErrorPath hfs fp) ioErr
329-
330- {- ------------------------------------------------------------------------------
331- Hard links
332- -------------------------------------------------------------------------------}
333-
334- createHardLinkIO ::
335- HasFS IO HandleIO
336- -> (FilePath -> FilePath -> IO () )
337- -> (FsPath -> FsPath -> IO () )
338- createHardLinkIO hfs f = \ source target -> do
339- source' <- FS. unsafeToFilePath hfs source -- shouldn't fail because we are in IO
340- target' <- FS. unsafeToFilePath hfs target -- shouldn't fail because we are in IO
341- f source' target'
0 commit comments