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

provide posix semantics for uv_fs_unlink on Windows #3839

Open
vtjnash opened this issue Nov 29, 2022 · 3 comments · May be fixed by #4318
Open

provide posix semantics for uv_fs_unlink on Windows #3839

vtjnash opened this issue Nov 29, 2022 · 3 comments · May be fixed by #4318

Comments

@vtjnash
Copy link
Member

vtjnash commented Nov 29, 2022

Possibly due to C++20, there are now documented flags that force posix-compliant behavior on Windows when deleting a file. It is not documented when this was added to the Windows kernel. (It is also possible the behavior of DeleteFile and/or DeleteFileEx has changed according to random user comments on the internet, although the documentation for those functions still claim not to provide posix-behavior here.) But while browsing the documentation site, I discovered it is now possible to request posix-compatible deletion semantics via:

https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddk/ns-ntddk-_file_disposition_information_ex

We can infer some of the dates where this is first available from the comments on the official C++20 STL implementation (apache-2 license), such as microsoft/STL#1559

1809 | Redstone 5 | October 2018 Update (added FILE_DISPOSITION_FLAG_IGNORE_READONLY_ATTRIBUTE)
1607 | Redstone | Anniversary Update (added FILE_DISPOSITION_FLAG_POSIX_SEMANTICS)

It is then possible to detect the error if these functions/types are not available at runtime for the filesystem or operating system, and fallback to the current code.

@bnoordhuis
Copy link
Member

Interesting find. My Cliffs notes:

  • they're set on the HANDLE with SetFileInformationByHandle(FileDispositionInfoEx), like fcntl/ioctl
  • GetLastError is ERROR_NOT_SUPPORTED when it's, er, not supported
  • FileDispositionInfoEx == 21
  • FILE_DISPOSITION_INFO_EX is a single DWORD
  • FILE_DISPOSITION_FLAG_POSIX_SEMANTICS == 2
  • FILE_DISPOSITION_FLAG_IGNORE_READONLY_ATTRIBUTE == 16

@vtjnash
Copy link
Member Author

vtjnash commented Dec 11, 2022

Possibly also a similar change for rename using SetFileInformationByHandle with FileRenameInfoEx and FILE_RENAME_FLAG_POSIX_SEMANTICS, though curiously the microsoft employees rejected using it to fix their stl bugs listed here microsoft/STL#2053 for being less-posix-compliant than our current implementation

@IanButterworth
Copy link

Just adding @vtjnash's helpful comment from here

The Rust implementation of that change was here rust-lang/rust@5ab67bf#diff-e8df55f38a9a224cf1cfd40e6c535535aa66e8073cc8d9b959308659ba1de1f9R572-R577

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

Successfully merging a pull request may close this issue.

3 participants