`std::fs::DirEntry::metadata` should clarify it might not be the latest metadata in Windows
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Location
Summary
When using the std::fs::DirEntry::metadata function on Windows, the metadata returned by a DirEntry might be different than the actual file metadata.
This can be seen in the following code:
fn main() {
std::fs::write("./tmp/file1", "file 1 content").unwrap();
std::thread::sleep(std::time::Duration::from_millis(250));
std::fs::read("./tmp/file1").unwrap();
for entry in std::fs::read_dir("./tmp").unwrap() {
let entry = entry.unwrap();
let entry_meta = entry.metadata().unwrap();
let direct_meta = entry.path().metadata().unwrap();
assert_eq!(
entry_meta.accessed().unwrap(),
direct_meta.accessed().unwrap()
);
}
}
The assert fails because the metadata is different when retrieved from the DirEntry and from using the path directly. I'm not entirely sure of why this behaviour occurs on Windows (I'm guessing it's something to do about how the metadata is retrieved in a DirEntry vs retrieving it by path).
I think this behaviour should be documented in case the latest metadata of a file is needed, so a DirEntry metadata can't be relied at all times on Windows.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked std::fs::DirEntry::metadata API documentation and inspect the surrounding implementation or platform-specific notes to confirm the Windows behavior. Clarify that DirEntry metadata may not be current on Windows and explain when path-based metadata should be used; verify that the documentation builds successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation, operating-systems
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100