Skip to content

Windows: std::fs::read_dir returns NotFound for empty volume #120040

Closed
@ChrisDenton

Description

@ChrisDenton

This was reported on discord by @Fulgen301 who pointed out that the C++ STL has a similar issue.

Example:

// where `path` is a path to an empty volume.
let path = r"\\?\Volume{e6d42597-fcdc-4856-b3c2-482fe652f1df}\";
std::fs::read_dir(path).unwrap();

prints:

called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }

It should return success but the returned iterator will have no items.

Basically if you use FindFirstFileW on a completely empty volume then it will return ERROR_FILE_NOT_FOUND. Rust should interpret this as being an empty iteration and not return an error to the user. Note that empty directories do not return an error so this behaviour was overlooked.

We need to add some extra logic to this else:

} else {
Err(Error::last_os_error())
}

Metadata

Metadata

Assignees

Labels

O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions