From 8afc0282f28e73cf78d1bd7b11d78fd853ae2036 Mon Sep 17 00:00:00 2001 From: Yomain Date: Tue, 11 Jul 2023 19:51:04 +0200 Subject: Fix crash when cwd is deleted (#7185) --- helix-core/src/path.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'helix-core') diff --git a/helix-core/src/path.rs b/helix-core/src/path.rs index efa46c46..85c60255 100644 --- a/helix-core/src/path.rs +++ b/helix-core/src/path.rs @@ -88,7 +88,7 @@ pub fn get_normalized_path(path: &Path) -> PathBuf { pub fn get_canonicalized_path(path: &Path) -> std::io::Result { let path = expand_tilde(path); let path = if path.is_relative() { - std::env::current_dir().map(|current_dir| current_dir.join(path))? + helix_loader::current_working_dir().join(path) } else { path }; @@ -99,9 +99,7 @@ pub fn get_canonicalized_path(path: &Path) -> std::io::Result { pub fn get_relative_path(path: &Path) -> PathBuf { let path = PathBuf::from(path); let path = if path.is_absolute() { - let cwdir = std::env::current_dir() - .map(|path| get_normalized_path(&path)) - .expect("couldn't determine current directory"); + let cwdir = get_normalized_path(&helix_loader::current_working_dir()); get_normalized_path(&path) .strip_prefix(cwdir) .map(PathBuf::from) @@ -142,7 +140,7 @@ pub fn get_relative_path(path: &Path) -> PathBuf { /// ``` /// pub fn get_truncated_path>(path: P) -> PathBuf { - let cwd = std::env::current_dir().unwrap_or_default(); + let cwd = helix_loader::current_working_dir(); let path = path .as_ref() .strip_prefix(cwd) -- cgit v1.2.3-70-g09d2