-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
File::create fails on hidden files on Windows #115745
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`C-bugCategory: This is a bug.Category: This is a bug.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`C-bugCategory: This is a bug.Category: This is a bug.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.
Reported on discord, using
OpenOptions::new().write(true).create(true).truncate(true).open(&path)will fail on Windows if the file is hidden. This also affects methods likeFile::createorfs::writethat open the file the same way.The reason for this is that we use
CREATE_ALWAYS, which has strange behaviour:So to make it work the caller needs to match the requested attributes to the existing attributes at the time of opening.
Possible solution
It was suggested we could instead use
OPEN_ALWAYSand then manually truncate the file usingSetFileInformationByHandleto set theFILE_ALLOCATION_INFOto zero.