Skip to content

Commit f996a72

Browse files
committed
WINIO: Add support for WINIO to Cabal.
1 parent b744cde commit f996a72

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Cabal/Distribution/Compat/Internal/TempFile.hs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import Distribution.Compat.Exception
1212
import System.FilePath ((</>))
1313
import Foreign.C (CInt, eEXIST, getErrno, errnoToIOError)
1414

15-
import System.IO (Handle, openTempFile, openBinaryTempFile)
15+
import System.IO (Handle, openTempFile, openBinaryTempFile
16+
#if defined(__IO_MANAGER_WINIO__)
17+
, openBinaryTempFileWithDefaultPermissions
18+
#endif
19+
)
1620
import Data.Bits ((.|.))
1721
import System.Posix.Internals (c_open, c_close, o_CREAT, o_EXCL, o_RDWR,
1822
o_BINARY, o_NONBLOCK, o_NOCTTY,
@@ -36,10 +40,17 @@ import qualified System.Posix
3640
-- TODO: This file should probably be removed.
3741

3842
-- This is a copy/paste of the openBinaryTempFile definition, but
39-
-- if uses 666 rather than 600 for the permissions. The base library
40-
-- needs to be changed to make this better.
43+
-- if uses 666 rather than 600 for the permissions. Newer versions
44+
-- of base have a new function with this behavior which we use on
45+
-- Windows when the new IO manager is used.
4146
openNewBinaryFile :: FilePath -> String -> IO (FilePath, Handle)
4247
openNewBinaryFile dir template = do
48+
-- This method can't be used under WINIO. Also the current implementation has
49+
-- thread safety issues depending on which GHC is used. On newer GHC's let's
50+
-- use the built in one.
51+
#if defined(__IO_MANAGER_WINIO__)
52+
openBinaryTempFileWithDefaultPermissions dir template
53+
#else
4354
pid <- c_getpid
4455
findTempName pid
4556
where
@@ -95,6 +106,8 @@ pathSeparator = '\\'
95106
#else
96107
pathSeparator = '/'
97108
#endif
109+
-- /* __IO_MANAGER_WINIO__ */
110+
#endif
98111

99112
-- FIXME: Copied from GHC.Handle
100113
std_flags, output_flags, rw_flags :: CInt

0 commit comments

Comments
 (0)