Call set_pwd_per_drive() within stack::set_cwd()

This commit is contained in:
Zhenping Zhao
2024-11-21 22:14:54 -08:00
parent 444d55fd9d
commit 884214ecb4
5 changed files with 8 additions and 9 deletions

View File

@ -858,8 +858,6 @@ fn do_auto_cd(
report_shell_error(engine_state, &err);
return;
};
// Let PWD-per-drive sync with auto_cd target
let _ = nu_path::set_pwd_per_drive(PathBuf::from(path.clone()).as_path());
let cwd = Value::string(cwd, span);
let shells = stack.get_env_var(engine_state, "NUSHELL_SHELLS");

View File

@ -114,8 +114,6 @@ impl Command for Cd {
//FIXME: this only changes the current scope, but instead this environment variable
//should probably be a block that loads the information from the state in the overlay
PermissionResult::PermissionOk => {
// Let PWD-per-drive sync with cd target
let _ = nu_path::set_pwd_per_drive(path.as_path());
stack.set_cwd(path)?;
Ok(PipelineData::empty())
}

View File

@ -280,8 +280,9 @@ pub mod pwd_per_drive_singleton {
use super::*;
/// set_pwd_per_drive
/// record PWD for drive, path must be absolute path
/// On Windows, record PWD for drive, path must be absolute path
/// return Ok(()) if succeeded, otherwise error message
/// Other platforms, return Ok(())
pub fn set_pwd_per_drive(_path: &Path) -> Result<(), String> {
cfg_if::cfg_if! { if #[cfg(target_os="windows")] {
@ -317,7 +318,7 @@ pub mod pwd_per_drive_singleton {
}
cfg_if::cfg_if! { if #[cfg(target_os="windows")] {
/// Helper only used on windows, if input path is relative path
/// Helper only used on Windows, if input path is relative path
/// with drive letter, it can be expanded with PWD-per-drive.
fn need_expand_pwd_per_drive(_path: &Path) -> bool {
if let Some(path_str) = _path.to_str() {

View File

@ -726,6 +726,8 @@ impl Stack {
let path = nu_path::strip_trailing_slash(path);
let value = Value::string(path.to_string_lossy(), Span::unknown());
self.add_env_var("PWD".into(), value);
// Sync with PWD-per-drive
let _ = nu_path::set_pwd_per_drive(&path);
Ok(())
}
}

View File

@ -22,7 +22,7 @@ use log::{trace, Level};
use miette::Result;
use nu_cli::gather_parent_env_vars;
use nu_lsp::LanguageServer;
use nu_path::{canonicalize_with, set_pwd_per_drive};
use nu_path::canonicalize_with;
use nu_protocol::{
engine::EngineState, report_shell_error, ByteStream, PipelineData, ShellError, Span, Spanned,
Value,
@ -78,8 +78,8 @@ fn main() -> Result<()> {
// Get the current working directory from the environment.
let init_cwd = current_dir_from_environment();
// Let PWD-per-drive sync from startup
let _ = set_pwd_per_drive(init_cwd.as_ref());
// Sync with PWD-per-drive
let _ = nu_path::set_pwd_per_drive(init_cwd.as_ref());
// Custom additions
let delta = {