Skip to content

read_dir has unexpected behavior for "" #114149

Closed
@justinlovinger

Description

Path::parent returns Some("") for relative paths like foo.txt, but read_dir throws an error when given "", so code like if let Some(parent) = path.parent() { std::fs::read_dir(parent) } fails for files in the working directory.

Additionally, calling read_dir on a relative file without a ./ prefix returns file paths without ./ prefixes, but there is no way to achieve similar behavior for the working directory because read_dir("") throws an error. read_dir(".") returns file paths with ./ prefixes and is not a solution.

This was tested on Unix, and may be Unix-specific, but I lack a Windows machine to easily test against.

Metadata

Assignees

No one assigned

    Labels

    A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`S-waiting-on-teamStatus: Awaiting decision from the relevant subteam (see the T-<team> label).T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions