diff options
author | Yomain | 2023-07-11 17:51:04 +0000 |
---|---|---|
committer | GitHub | 2023-07-11 17:51:04 +0000 |
commit | 8afc0282f28e73cf78d1bd7b11d78fd853ae2036 (patch) | |
tree | 6742e141f051d352ebe7017f15805613670864b9 /helix-core | |
parent | 1adb19464f002926e1042027b41acef4c81585f6 (diff) |
Fix crash when cwd is deleted (#7185)
Diffstat (limited to 'helix-core')
-rw-r--r-- | helix-core/src/path.rs | 8 |
1 files changed, 3 insertions, 5 deletions
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<PathBuf> { 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<PathBuf> { 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<P: AsRef<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) |