Skip to content

openTempFile fails on Windows if a directory exists with the file name it tries

The program below works on Linux but fails on Windows with "permission denied" from the second openTempFile.

I think the reason is that findTempName in the openTempFile source doesn't get eEXIST when a directory with the same name exists, so it fails instead of trying again.

The real use case behind this code is making temp directories on multiple threads simultaneously.

import Prelude
import System.IO
import System.Directory

main :: IO ()
main = do
    dir <- getTemporaryDirectory
    (npath1, handle1) <- openTempFile dir "tmp"
    hClose handle1
    removeFile npath1
    createDirectory npath1
    (npath2, handle2) <- openTempFile dir "tmp"
    return ()
Trac metadata
Trac field Value
Version 7.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC ganesh@earth.li
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information