Proposal Details

It is not possible to change sharemode when opening a file on Windows.

Sharemode is defined here: syscall_windows.go#L396 Sharemode is used here: syscall_windows.go#L436

Why this is required ?

I use the API LockFileEx to lock my file. However, if another process Open the file with CREATE_ALWAYS, which software usually do, it will truncate the file.

To protect against that, it is required to Open the file without the flag FILE_SHARE_WRITE.

See that: https://stackoverflow.com/a/8191665

Proposal

Since we usually want the flags FILE_SHARE_READ and FILE_SHARE_WRITE, and to not break existing API, I propose to add two flags:

  • NO_FILE_SHARE_READ -> to remove the flag FILE_SHARE_READ
  • NO_FILE_SHARE_WRITE -> to remove the flag FILE_SHARE_WRITE