openFile sharing permissions are inconsistent across platforms
System.IO.openFile seems to have inconsistent behaviour across platforms regarding file sharing permissions.
Given this program:
{-# LANGUAGE CPP #-}
import System.IO
import System.Process
main = do
h <- openFile "file.txt" WriteMode
hPutStrLn h "Success! I can see the file's contents."
hFlush h
#ifdef mingw32_HOST_OS
system "type file.txt"
#else
system "cat file.txt"
#endif
hClose h
Running under Ubuntu 10.04 / GHC 6.12.1, I get:
$ runghc openFile.hs
Success! I can see the file's contents.
Running under Windows 7 / GHC 6.12.3, I get:
> runghc openFile.hs
The process cannot access the file because it is being used by another process.
In my opinion the behaviour exhibited by Linux is preferable because it allows for log files to be written by long running processes. These log files can then be inspected externally while the Haskell process is still running.
The Snap Framework (snapframework.com) does this and it works great on Linux / Mac OS, but on Windows the log files cannot be viewed until after the server is shut down.
Trac metadata
Trac field | Value |
---|---|
Version | 6.12.3 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |