[Issue 2429] std.stream.File incorrect flag parsing and sharing mode

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 27 15:15:58 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2429





------- Comment #1 from jason at spashett.com  2008-11-27 17:15 -------
I have tested, and reviwed the new parseMode function. 

It is now possible to open for read (e.g. tail -f) a file that is being written
to by a d program using FileMode.Out

Unfortunatly it's still not possible to open a file for read, that is being
written to by another process.

for example:
In dos window #1:
C:\temp>copy /y con test.txt

In dos window #2:
C:\temp>test.exe
Error: Cannot open or create file 'test.txt'

test.d
---------------------
import std.stream;
import std.stdio;
void main()
{
        auto f = new File("test.txt", FileMode.In);
        char[] s;
        s = readln();
}
---------------------


Again, changing the first line in main to:
auto f = new File("test.txt", FileMode.In | FileMode.Out);

is a workaround, but I feel isn't correct as I am not opening it for write
access. The workaround causes the sharing mode to be FILE_SHARE_READ |
FILE_SHARE_WRITE 

I belive, reasonably, that the share mode should always have these two flags
set no matter what the FileMode is, read or write, so that there are no sharing
confilicts on windows.

It is sometimes useful to write to a file with one process, while reading from
it with another process. Read/write races or conflicts may occur, but that is
up to the user to deal with. 


-- 



More information about the Digitalmars-d-bugs mailing list