Skip to content

Document canonicalization in std::env::current_dir #93598

Closed
@AZMCode

Description

@AZMCode

As of now, the stable and nightly documentation on std::env::current_dir only states

Returns the current working directory as a PathBuf.

And proceeds to note a couple of errors the function may fail with.
This does not mention the fact that (as far as I am aware, testing on Linux) the path is also canonicalized, having resolved all symlinks in any segment of the path. I'd imagine not documenting this behavior could lead to confusion and/or bugs, if it already hasn't.

I tried this code within a symlink folder /example/symlink/here pointing to /symlink/target/here:

println!("{:#?}",std::env::current_dir().unwrap())

I expected to see get the output: "/example/symlink/here"
Instead, this was output: "/symlink/target/here"

Currently using the nightly compiler.

For obvious reasons, there's no backtrace.

Update: Read a bit through the code and realized this behavior might be libc-dependent
ldd --version on my system returns ldd (GNU libc) 2.33

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.T-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