@@ -10,16 +10,21 @@ module Distribution.Compat.Internal.TempFile (
10
10
import Distribution.Compat.Exception
11
11
12
12
import System.FilePath ((</>) )
13
- import Foreign.C (CInt , eEXIST , getErrno , errnoToIOError )
14
13
15
14
import System.IO (Handle , openTempFile , openBinaryTempFile )
15
+ #if defined(__IO_MANAGER_WINIO__)
16
+ import System.IO (openBinaryTempFileWithDefaultPermissions )
17
+ #else
18
+ import Control.Exception (onException )
16
19
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 )
21
21
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 )
23
28
24
29
#if defined(mingw32_HOST_OS) || defined(ghcjs_HOST_OS)
25
30
import System.Directory ( createDirectory )
@@ -36,10 +41,17 @@ import qualified System.Posix
36
41
-- TODO: This file should probably be removed.
37
42
38
43
-- 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.
41
47
openNewBinaryFile :: FilePath -> String -> IO (FilePath , Handle )
42
48
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
43
55
pid <- c_getpid
44
56
findTempName pid
45
57
where
@@ -88,19 +100,21 @@ openNewBinaryFile dir template = do
88
100
| last a == pathSeparator = a ++ b
89
101
| otherwise = a ++ [pathSeparator] ++ b
90
102
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
+
91
109
-- FIXME: Should use System.FilePath library
92
110
pathSeparator :: Char
93
111
#ifdef mingw32_HOST_OS
94
112
pathSeparator = ' \\ '
95
113
#else
96
114
pathSeparator = ' /'
97
115
#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
104
118
105
119
createTempDirectory :: FilePath -> String -> IO FilePath
106
120
createTempDirectory dir template = do
0 commit comments