From 8a21e7be411e1fa01c2c1c22b42f4ad0eda1be69 Mon Sep 17 00:00:00 2001 From: Adithya Kumar Date: Mon, 28 Oct 2024 16:35:04 +0530 Subject: [PATCH] 2 --- .../Internal/FileSystem/Posix/File.hs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/src/Streamly/Internal/FileSystem/Posix/File.hs b/core/src/Streamly/Internal/FileSystem/Posix/File.hs index 1f63db6285..9a6336079f 100644 --- a/core/src/Streamly/Internal/FileSystem/Posix/File.hs +++ b/core/src/Streamly/Internal/FileSystem/Posix/File.hs @@ -13,13 +13,13 @@ import Data.Bits ((.|.)) import Foreign.C.Error (getErrno, eINTR, errnoToIOError) import Foreign.C.String (CString) import Foreign.C.Types (CInt(..)) -import Streamly.Internal.FileSystem.Path (Path) +import Streamly.Internal.FileSystem.PosixPath (PosixPath) import System.IO (IOMode(..), Handle) import System.Posix.IO (fdToHandle) import System.Posix.Types (Fd(..), CMode(..), FileMode) import qualified Streamly.Internal.Data.Array as Array -import qualified Streamly.Internal.FileSystem.Path as Path +import qualified Streamly.Internal.FileSystem.PosixPath as Path ------------------------------------------------------------------------------- -- Posix @@ -71,7 +71,7 @@ defaultExistingFileFlags = defaultFileFlags { noctty = True, nonBlock = True, cr defaultFileFlags' :: OpenFileFlags defaultFileFlags' = defaultFileFlags { noctty = True, nonBlock = True } -withFilePath :: Path -> (CString -> IO a) -> IO a +withFilePath :: PosixPath -> (CString -> IO a) -> IO a withFilePath p = Array.asCStringUnsafe (Path.toChunk p) @@ -116,18 +116,18 @@ foreign import capi unsafe "HsUnix.h openat" -- |Open and optionally create this file. See 'System.Posix.Files' -- for information on how to use the 'FileMode' type. -openFd :: Path +openFd :: PosixPath -> OpenMode -> OpenFileFlags -> IO Fd openFd = openFdAt Nothing throwErrnoPathIfMinus1Retry :: (Eq a, Num a) - => String -> Path -> IO a -> IO a + => String -> PosixPath -> IO a -> IO a throwErrnoPathIfMinus1Retry loc path f = do throwErrnoPathIfRetry (== -1) loc path f -throwErrnoPathIfRetry :: (a -> Bool) -> String -> Path -> IO a -> IO a +throwErrnoPathIfRetry :: (a -> Bool) -> String -> PosixPath -> IO a -> IO a throwErrnoPathIfRetry pr loc rpath f = do res <- f @@ -139,7 +139,7 @@ throwErrnoPathIfRetry pr loc rpath f = else throwErrnoPath loc rpath else return res -throwErrnoPath :: String -> Path -> IO a +throwErrnoPath :: String -> PosixPath -> IO a throwErrnoPath loc path = do errno <- getErrno @@ -155,7 +155,7 @@ throwErrnoPath loc path = -- directory tree that would otherwise become inaccessible after dropping -- privileges. openFdAt :: Maybe Fd -- ^ Optional directory file descriptor - -> Path -- ^ Pathname to open + -> PosixPath -- ^ Pathname to open -> OpenMode -- ^ Read-only, read-write or write-only -> OpenFileFlags -- ^ Append, exclusive, truncate, etc. -> IO Fd @@ -163,7 +163,7 @@ openFdAt fdMay name how flags = withFilePath name $ \str -> throwErrnoPathIfMinus1Retry "openFdAt" name $ openat_ fdMay str how flags -openExistingFile_ :: OpenFileFlags -> Path -> IOMode -> IO Handle +openExistingFile_ :: OpenFileFlags -> PosixPath -> IOMode -> IO Handle openExistingFile_ df fp iomode = fdToHandle =<< case iomode of ReadMode -> open ReadOnly df WriteMode -> open WriteOnly df { trunc = True } @@ -173,13 +173,13 @@ openExistingFile_ df fp iomode = fdToHandle =<< case iomode of open = openFd fp -- | Open an existing file and return the 'Handle'. -openExistingFile :: Path -> IOMode -> IO Handle +openExistingFile :: PosixPath -> IOMode -> IO Handle openExistingFile = openExistingFile_ defaultExistingFileFlags -openExistingFileWithCloseOnExec :: Path -> IOMode -> IO Handle +openExistingFileWithCloseOnExec :: PosixPath -> IOMode -> IO Handle openExistingFileWithCloseOnExec = openExistingFile_ defaultExistingFileFlags { cloexec = True } -openFile_ :: OpenFileFlags -> Path -> IOMode -> IO Handle +openFile_ :: OpenFileFlags -> PosixPath -> IOMode -> IO Handle openFile_ df fp iomode = fdToHandle =<< case iomode of ReadMode -> open ReadOnly df WriteMode -> open WriteOnly df { trunc = True, creat = Just 0o666 } @@ -189,8 +189,8 @@ openFile_ df fp iomode = fdToHandle =<< case iomode of open = openFd fp -- | Open a file and return the 'Handle'. -openFile :: Path -> IOMode -> IO Handle +openFile :: PosixPath -> IOMode -> IO Handle openFile = openFile_ defaultFileFlags' -openFileWithCloseOnExec :: Path -> IOMode -> IO Handle +openFileWithCloseOnExec :: PosixPath -> IOMode -> IO Handle openFileWithCloseOnExec = openFile_ defaultFileFlags' { cloexec = True }