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

correctly handle opening helix inside symlinked directory #10728

Merged
merged 2 commits into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions helix-stdx/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ pub fn current_working_dir() -> PathBuf {
return path.clone();
}

let path = std::env::current_dir()
.map(crate::path::normalize)
.expect("Couldn't determine current working directory");
let mut cwd = CWD.write().unwrap();
*cwd = Some(path.clone());
// implementation of crossplatform pwd -L
// we want pwd -L so that symlinked directories are handled correctly
let mut cwd = std::env::current_dir().expect("Couldn't determine current working directory");

let pwd = std::env::var_os("PWD");
#[cfg(windows)]
let pwd = pwd.or_else(|| std::env::var_os("CD"));

if let Some(pwd) = pwd.map(PathBuf::from) {
if pwd.canonicalize().ok().as_ref() == Some(&cwd) {
cwd = pwd;
}
}
let mut dst = CWD.write().unwrap();
*dst = Some(cwd.clone());

path
cwd
}

pub fn set_current_working_dir(path: impl AsRef<Path>) -> std::io::Result<()> {
Expand Down
Loading