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

           Summary: std.stream.File incorrect flag parsing and sharing mode
           Product: D
           Version: 1.037
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


In stream.d parseMode is incorrect/inconsistent for windows platforms. 

Firstly the share mode is not set to FILE_SHARE_READ in the case when the file
is opened for writing. This make it impossible to view log files while they are
written to.

Second it is possible to specify combinations of FileMode options which will
override each others behaviour and create a mixture.

Hence it's possible to 'fix' the sharing option but opening a file with:
FileMode.OutNew |  FileMode.In to enable sharing even though the file will
never be read from.

I can't see any indication that this things are by design, and perhaps the
windows sharing mode should always include READ and WRITE sharing to be more
portable. Either that or allow sharing flags in the file mode.



private void parseMode(int mode,
                         out int access,
                         out int share,
                         out int createMode) {
    version (Win32) {
      if (mode & FileMode.In) {
        access |= GENERIC_READ;
        share |= FILE_SHARE_READ;
        createMode = OPEN_EXISTING;
      }
      if (mode & FileMode.Out) {
        access |= GENERIC_WRITE;
        createMode = OPEN_ALWAYS; // will create if not present
      }
      if ((mode & FileMode.OutNew) == FileMode.OutNew) {
        createMode = CREATE_ALWAYS; // resets file
      }
    }


-- 

Reply via email to