Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AZMCode opened this issue Feb 2, 2022 · 3 comments · Fixed by #93635
Closed

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

AZMCode opened this issue Feb 2, 2022 · 3 comments · Fixed by #93635
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@AZMCode
Copy link

AZMCode commented Feb 2, 2022

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

@AZMCode AZMCode added the C-bug Category: This is a bug. label Feb 2, 2022
@hkratz
Copy link
Contributor

hkratz commented Feb 3, 2022

For UNIX Rust just calls getcwd() and that behavior is documented in the POSIX spec, so it will be the same on all conforming implementations. We should document which platform-specific function we call here just like we do with other filesystem functions (e.g. here).

@rustbot label T-libs A-docs

@rustbot rustbot added A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 3, 2022
@GuillaumeGomez
Copy link
Member

It was also missing for set_current_dir so I opened #93635 for both.

@AZMCode
Copy link
Author

AZMCode commented Feb 4, 2022

Thanks a lot

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 11, 2022
…c-info, r=Amanieu

Add missing platform-specific information on current_dir and set_current_dir

Fixes rust-lang#93598.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 11, 2022
…c-info, r=Amanieu

Add missing platform-specific information on current_dir and set_current_dir

Fixes rust-lang#93598.
@bors bors closed this as completed in 15d71cf Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants