Commit 7bc7cf1b authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Fix building with ghc-6.12

parent 33cff7b6
......@@ -8,8 +8,19 @@ module Distribution.Compat.TempFile (
) where
import System.FilePath ((</>))
import System.Posix.Internals (mkdir, c_getpid)
import Foreign.C (withCString, getErrno, eEXIST, errnoToIOError)
#ifdef mingw32_HOST_OS
import System.Directory (createDirectory)
#else
import System.Posix.Directory (createDirectory)
#endif
import System.IO.Error (try, isAlreadyExistsError)
#if __NHC__
import System.Posix.Types (CPid(..))
foreign import ccall unsafe "getpid" c_getpid :: IO CPid
#else
import System.Posix.Internals (c_getpid)
#endif
createTempDirectory :: FilePath -> String -> IO FilePath
createTempDirectory dir template = do
......@@ -18,11 +29,15 @@ createTempDirectory dir template = do
where
findTempName x = do
let dirpath = dir </> template ++ show x
res <- withCString dirpath $ \s -> mkdir s 0o700
if res == 0
then return dirpath
else do
errno <- getErrno
if errno == eEXIST
then findTempName (x+1)
else ioError (errnoToIOError "createTempDirectory" errno Nothing (Just dir))
r <- try $ mkPrivateDir dirpath
case r of
Right _ -> return dirpath
Left e | isAlreadyExistsError e -> findTempName (x+1)
| otherwise -> ioError e
mkPrivateDir :: String -> IO ()
#ifdef mingw32_HOST_OS
mkPrivateDir s = System.Directory.createDirectory s
#else
mkPrivateDir s = System.Posix.Directory.createDirectory s 0o700
#endif
......@@ -94,8 +94,8 @@ Executable cabal
directory >= 1 && < 1.1,
pretty >= 1 && < 1.1,
random >= 1 && < 1.1,
containers >= 0.1 && < 0.3,
array >= 0.1 && < 0.3,
containers >= 0.1 && < 0.4,
array >= 0.1 && < 0.4,
old-time >= 1 && < 1.1,
time >= 1.1 && < 1.2
......@@ -108,5 +108,5 @@ Executable cabal
build-depends: Win32 >= 2 && < 3
cpp-options: -DWIN32
else
build-depends: unix >= 1.0 && < 2.4
build-depends: unix >= 1.0 && < 2.5
extensions: CPP
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment