Fix cd'ing to symlinked directories (#1651)

* fix: absolutize path against its parent if it was a symlink.

On Linux this happens because Rust calls readlink but doesn't canonicalize the resultant path.

* feat: playground function to create symlinks

* fix: use playground dirs

* feat: test for #1631, shift tests names
This commit is contained in:
Kevin Del Castillo
2020-04-25 01:09:00 -05:00
committed by GitHub
parent e7a4f31b38
commit 846a779516
3 changed files with 86 additions and 31 deletions

View File

@ -49,12 +49,16 @@ where
P: AsRef<Path>,
Q: AsRef<Path>,
{
let canonicalized = absolutize(relative_to, path);
let path = match std::fs::read_link(&canonicalized) {
Ok(resolved) => resolved,
let absolutized = absolutize(&relative_to, path);
let path = match std::fs::read_link(&absolutized) {
Ok(resolved) => {
let parent = absolutized.parent().unwrap_or(&absolutized);
absolutize(parent, resolved)
}
Err(e) => {
if canonicalized.exists() {
canonicalized
if absolutized.exists() {
absolutized
} else {
return Err(e);
}