Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[filestream][win] feature request: support dwShareMode FILE_SHARE_DELETE #1473

Open
Trafo opened this issue Aug 5, 2020 · 2 comments
Open

Comments

@Trafo
Copy link

Trafo commented Aug 5, 2020

At the moment it is not possible to set the file protection mode of a stream to a value which enables FILE_SHARE_DELETE. But from my point of view, for no reasons.

My suggestion is to change the code inside of the _get_create_flags method (fileio_win32.cpp: 126) from

    // C++ specifies what permissions to deny, Windows which permissions to give,
    dwShareMode = 0x3;
    switch (prot)
    {
        case _SH_DENYRW: dwShareMode = 0x0; break;
        case _SH_DENYWR: dwShareMode = 0x1; break;
        case _SH_DENYRD: dwShareMode = 0x2; break;
    }

to

    // C++ specifies what permissions to deny, Windows which permissions to give,
    dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
    switch (prot)
    {
        case _SH_DENYRW: dwShareMode = 0x0; break;
        case _SH_DENYWR: dwShareMode = FILE_SHARE_READ; break;
        case _SH_DENYRD: dwShareMode = FILE_SHARE_WRITE; break;
    }

It is debatable if _SH_DENYRD and _SH_DENYRW enable FILE_SHARE_DELETE as well. But I expect in case of _SH_DENYNO (that is the default mode of cpprest), that no restrictions are left. Additionally, after this change, the behaving of this library would be the same under Unix and Windows. At the moment it is not, because under windows I can not remove/rename a file with open file stream but under Unix that is possible.

@garethsb
Copy link
Contributor

garethsb commented Aug 5, 2020

For platform consistency, it might be that including FILE_SHARE_DELETE always would be the way to go, though the behaviour is still not identical to Linux and macOS. See golang/go#32088.

@Trafo
Copy link
Author

Trafo commented Aug 7, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants