- -- the case that the dir did exist but another process deletes it
- -- before we can check that it did indeed exist.
- | isAlreadyExistsError e -> do exists <- doesDirectoryExist dir
- if exists then return ()
- else throw e
+ -- the case that the dir did exist but another process deletes the
+ -- directory and creates a file in its place before we can check
+ -- that the directory did indeed exist.
+ | isAlreadyExistsError e ->
+ (withFileStatus "createDirectoryIfMissing" dir $ \st -> do
+ isDir <- isDirectory st
+ if isDir then return ()
+ else throw e
+ ) `catch` ((\_ -> return ()) :: IOException -> IO ())