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

Regression: can't stat files on Windows if file is open from another process #290

Closed
toh-ableton opened this issue Jul 12, 2023 · 2 comments

Comments

@toh-ableton
Copy link

If on Windows, one process has an open file handle to a file without FILE_SHARE_READ, trying to create a handle with GENERIC_READ in another process fails.

This means that creation_time, last_write_time fail with ERROR_SHARING_VIOLATION.

This regression was introduced in 1db4474 with this comment in the commit message:

Also, use GENERIC_READ access mode when we call GetFileTime on the handle
afterwards. GetFileTime documentation explicitly mentions that GENERIC_READ
is required for it.

While it is true that the GetFileTime documentation mentions this, this is obviously a bug in the documentation. Until boost 1.79, a value of 0 was passed for the dwDesiredAccess parameter, which apparently worked just fine and is also documented to work in the CreateFileW documentation:

If this parameter is zero, the application can query certain metadata such as file, directory, or device attributes without accessing that file or device, even if GENERIC_READ access would have been denied.

To fix this, the dwDesiredAccess parameter changes in creation_time and last_write_time need to be reverted, either to FILE_READ_ATTRIBUTES or to 0.

@Lastique
Copy link
Member

The thing is apparently these access modes are handled separately by each and every filesystem. What works on NTFS may not work on SMB or FAT or any other third party filesystem driver. The commit you referenced works around precisely such discrepancy in behavior. In a mess like this, at least following the documentation is the most reasonable way to go.

Re. CreateFileW, it only mentions file attributes. I do not think file times are considered as attributes.

@toh-ableton
Copy link
Author

@Lastique thanks for the quick fix! 💐

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