[Haskell-cafe] Exclusive mode in openFile

Gracjan Polak gracjanpolak at gmail.com
Wed Jun 29 12:59:02 CEST 2011


Max Bolingbroke <batterseapower <at> hotmail.com> writes:
>
http://hackage.haskell.org/packages/archive/unix/2.4.2.0/doc/html/System-Posix-IO.html.

Thanks for the link. I tried to use it:

Prelude System.Posix.IO> fd1 <- openFd "xxx.tmp" WriteOnly (Just 0666)
defaultFileFlags
Loading package unix-2.4.0.2 ... linking ... done.
Prelude System.Posix.IO> fd2 <- openFd "xxx.tmp" WriteOnly (Just 0666)
defaultFileFlags
Prelude System.Posix.IO> print (fd1,fd2)
(5,7)
Prelude System.Posix.IO> h1 <- fdToHandle fd1
Prelude System.Posix.IO> h2 <- fdToHandle fd2
*** Exception: openFile: resource busy (file is locked)

So I can open file twice. So far so good. Then I convert Fds to Handles and
second conversion fails.

I'm looking for file locking code in GHC.IO.* modules, but cannot find any.

How do I convince fdToHandle to create an independent handle to non-locked file?

-- 
Gracjan





More information about the Haskell-Cafe mailing list