-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Windows: opening file in append mode breaks locking (?) #54118
Copy link
Copy link
Closed
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`O-windowsOperating system: WindowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`O-windowsOperating system: WindowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I think that
std::fshas a bug in the interaction between theOpenOptionsand file locking on Windows.Consider the following test program, using the
fs2crate:On Windows 10 this fails for me:
If I use
.write(true)instead of.append(true), it works fine.I believe that what's happening here is that the append mode is setting too many flags. Here's the relevant code in the Windows FS implementation. Based on this MS doc page, my guess is that the Rust code is somehow interacting with the Windows
SYNCHRONIZEflag in a way that's causing problems.However, I'm not a native Windows dev so this isn't my area of expertise, and it's a bit tricky for me to investigate this in detail. But I can't find any evidence on the internet that the error above is an expected behavior.