Skip to content

Commit 67fedf7

Browse files
Keep only createFile in Windows File module
1 parent 45e350f commit 67fedf7

File tree

1 file changed

+30
-27
lines changed
  • core/src/Streamly/Internal/FileSystem/Windows

1 file changed

+30
-27
lines changed

core/src/Streamly/Internal/FileSystem/Windows/File.hs

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module Streamly.Internal.FileSystem.Windows.File
2-
( openExistingFile
3-
, openFile
4-
, openExistingFileWithCloseOnExec
5-
, openFileWithCloseOnExec
2+
( -- openExistingFile
3+
-- openFile
4+
createFile
5+
-- , openExistingFileWithCloseOnExec
6+
-- , openFileWithCloseOnExec
67
) where
78

89
-------------------------------------------------------------------------------
@@ -43,7 +44,6 @@ import qualified Streamly.Internal.Data.Array as Array
4344
foreign import WINDOWS_CCONV unsafe "windows.h CreateFileW"
4445
c_CreateFile :: LPCTSTR -> AccessMode -> ShareMode -> LPSECURITY_ATTRIBUTES -> CreateMode -> FileAttributeOrFlag -> HANDLE -> IO HANDLE
4546

46-
4747
-- | like failIf, but retried on sharing violations. This is necessary for many
4848
-- file operations; see
4949
-- https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/316609
@@ -81,6 +81,30 @@ createFile name access share mb_attr mode flag mb_h =
8181
failIfWithRetry (==iNVALID_HANDLE_VALUE) (unwords ["CreateFile",show name]) $
8282
c_CreateFile c_name access share (maybePtr mb_attr) mode flag (maybePtr mb_h)
8383

84+
{-
85+
maxShareMode :: Win32.ShareMode
86+
maxShareMode =
87+
Win32.fILE_SHARE_DELETE .|.
88+
Win32.fILE_SHARE_READ .|.
89+
Win32.fILE_SHARE_WRITE
90+
91+
writeShareMode :: Win32.ShareMode
92+
writeShareMode =
93+
Win32.fILE_SHARE_DELETE .|.
94+
Win32.fILE_SHARE_READ
95+
96+
toHandle :: WindowsPath -> IOMode -> Win32.HANDLE -> IO Handle
97+
#if defined(__IO_MANAGER_WINIO__)
98+
toHandle _ iomode h = (`onException` Win32.closeHandle h) $ do
99+
when (iomode == AppendMode ) $ void $ Win32.setFilePointerEx h 0 Win32.fILE_END
100+
Win32.hANDLEToHandle h
101+
#else
102+
toHandle fp iomode h = (`onException` Win32.closeHandle h) $ do
103+
when (iomode == AppendMode ) $ void $ Win32.setFilePointerEx h 0 Win32.fILE_END
104+
fd <- _open_osfhandle (fromIntegral (ptrToIntPtr h)) (#const _O_BINARY)
105+
fdToHandle' fd Nothing False (Path.toString fp) iomode True
106+
#endif
107+
84108
-- | Open a file and return the 'Handle'.
85109
openFile :: WindowsPath -> IOMode -> IO Handle
86110
openFile fp iomode = bracketOnError
@@ -121,17 +145,6 @@ openFile fp iomode = bracketOnError
121145
ReadWriteMode -> maxShareMode
122146
123147
124-
maxShareMode :: Win32.ShareMode
125-
maxShareMode =
126-
Win32.fILE_SHARE_DELETE .|.
127-
Win32.fILE_SHARE_READ .|.
128-
Win32.fILE_SHARE_WRITE
129-
130-
writeShareMode :: Win32.ShareMode
131-
writeShareMode =
132-
Win32.fILE_SHARE_DELETE .|.
133-
Win32.fILE_SHARE_READ
134-
135148
-- | Open an existing file and return the 'Handle'.
136149
openExistingFile :: WindowsPath -> IOMode -> IO Handle
137150
openExistingFile fp iomode = bracketOnError
@@ -182,14 +195,4 @@ openFileWithCloseOnExec = openFile
182195
openExistingFileWithCloseOnExec :: WindowsPath -> IOMode -> IO Handle
183196
openExistingFileWithCloseOnExec = openExistingFile
184197
185-
toHandle :: WindowsPath -> IOMode -> Win32.HANDLE -> IO Handle
186-
#if defined(__IO_MANAGER_WINIO__)
187-
toHandle _ iomode h = (`onException` Win32.closeHandle h) $ do
188-
when (iomode == AppendMode ) $ void $ Win32.setFilePointerEx h 0 Win32.fILE_END
189-
Win32.hANDLEToHandle h
190-
#else
191-
toHandle fp iomode h = (`onException` Win32.closeHandle h) $ do
192-
when (iomode == AppendMode ) $ void $ Win32.setFilePointerEx h 0 Win32.fILE_END
193-
fd <- _open_osfhandle (fromIntegral (ptrToIntPtr h)) (#const _O_BINARY)
194-
fdToHandle' fd Nothing False (Path.toString fp) iomode True
195-
#endif
198+
-}

0 commit comments

Comments
 (0)