Skip to content

Commit 63d0049

Browse files
authored
Merge pull request #6908 from phadej/pr-6848-ci-another-try
WINIO: Add support for WINIO to Cabal.
2 parents 3c7a222 + 580bf06 commit 63d0049

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

Cabal/Distribution/Compat/Internal/TempFile.hs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@ module Distribution.Compat.Internal.TempFile (
1010
import Distribution.Compat.Exception
1111

1212
import System.FilePath ((</>))
13-
import Foreign.C (CInt, eEXIST, getErrno, errnoToIOError)
1413

1514
import System.IO (Handle, openTempFile, openBinaryTempFile)
15+
#if defined(__IO_MANAGER_WINIO__)
16+
import System.IO (openBinaryTempFileWithDefaultPermissions)
17+
#else
18+
import Control.Exception (onException)
1619
import Data.Bits ((.|.))
17-
import System.Posix.Internals (c_open, c_close, o_CREAT, o_EXCL, o_RDWR,
18-
o_BINARY, o_NONBLOCK, o_NOCTTY,
19-
withFilePath, c_getpid)
20-
import System.IO.Error (isAlreadyExistsError)
20+
import Foreign.C (CInt, eEXIST, getErrno, errnoToIOError)
2121
import GHC.IO.Handle.FD (fdToHandle)
22-
import Control.Exception (onException)
22+
import System.Posix.Internals (c_open, c_close, o_EXCL, o_BINARY, withFilePath,
23+
o_CREAT, o_RDWR, o_NONBLOCK, o_NOCTTY)
24+
#endif
25+
26+
import System.Posix.Internals (c_getpid)
27+
import System.IO.Error (isAlreadyExistsError)
2328

2429
#if defined(mingw32_HOST_OS) || defined(ghcjs_HOST_OS)
2530
import System.Directory ( createDirectory )
@@ -36,10 +41,17 @@ import qualified System.Posix
3641
-- TODO: This file should probably be removed.
3742

3843
-- 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.
44+
-- it uses 666 rather than 600 for the permissions. Newer versions
45+
-- of base have a new function with this behavior which we use on
46+
-- Windows when the new IO manager is used.
4147
openNewBinaryFile :: FilePath -> String -> IO (FilePath, Handle)
4248
openNewBinaryFile dir template = do
49+
-- This method can't be used under WINIO. Also the current implementation has
50+
-- thread safety issues depending on which GHC is used. On newer GHC's let's
51+
-- use the built in one.
52+
#if defined(__IO_MANAGER_WINIO__)
53+
openBinaryTempFileWithDefaultPermissions dir template
54+
#else
4355
pid <- c_getpid
4456
findTempName pid
4557
where
@@ -88,19 +100,21 @@ openNewBinaryFile dir template = do
88100
| last a == pathSeparator = a ++ b
89101
| otherwise = a ++ [pathSeparator] ++ b
90102

103+
-- FIXME: Copied from GHC.Handle
104+
std_flags, output_flags, rw_flags :: CInt
105+
std_flags = o_NONBLOCK .|. o_NOCTTY
106+
output_flags = std_flags .|. o_CREAT
107+
rw_flags = output_flags .|. o_RDWR
108+
91109
-- FIXME: Should use System.FilePath library
92110
pathSeparator :: Char
93111
#ifdef mingw32_HOST_OS
94112
pathSeparator = '\\'
95113
#else
96114
pathSeparator = '/'
97115
#endif
98-
99-
-- FIXME: Copied from GHC.Handle
100-
std_flags, output_flags, rw_flags :: CInt
101-
std_flags = o_NONBLOCK .|. o_NOCTTY
102-
output_flags = std_flags .|. o_CREAT
103-
rw_flags = output_flags .|. o_RDWR
116+
-- /* __IO_MANAGER_WINIO__ */
117+
#endif
104118

105119
createTempDirectory :: FilePath -> String -> IO FilePath
106120
createTempDirectory dir template = do

0 commit comments

Comments
 (0)